home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / term43-source.lha / Extras / Source / term-Source.lha / termInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-18  |  108.8 KB  |  5,184 lines

  1. /*
  2. **    termInit.c
  3. **
  4. **    Program initialization and shutdown routines
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* This variable helps us to remember whether the fast!
  13.      * macro panel was open or not.
  14.      */
  15.  
  16. STATIC BYTE HadFastMacros = FALSE;
  17.  
  18.     /* Remember whether we did pen allocation or not. */
  19.  
  20. STATIC BYTE AllocatedPens = FALSE;
  21.  
  22.     /* SafeOpenLibrary(STRPTR Name,LONG Version):
  23.      *
  24.      *    Try to open a library, but if there already is
  25.      *    a version in memory that's older than the release
  26.      *    we want flush it out first.
  27.      */
  28.  
  29. struct Library * __regargs
  30. SafeOpenLibrary(STRPTR Name,LONG Version)
  31. {
  32.     struct Library *Base;
  33.  
  34.     Forbid();
  35.  
  36.         /* Is this library already in memory? */
  37.  
  38.     if(Base = (struct Library *)FindName(&SysBase -> LibList,FilePart(Name)))
  39.     {
  40.             /* An old release? */
  41.  
  42.         if(Base -> lib_Version < Version)
  43.         {
  44.                 /* Flush it out. */
  45.  
  46.             RemLibrary(Base);
  47.         }
  48.     }
  49.  
  50.     Permit();
  51.  
  52.         /* Now reopen the library. */
  53.  
  54.     return(OpenLibrary(Name,Version));
  55. }
  56.  
  57.     /* TTYResize():
  58.      *
  59.      *    Signal AmigaUW that the window size has changed.
  60.      */
  61.  
  62. VOID
  63. TTYResize()
  64. {
  65.     if(Window)
  66.     {
  67.         BOOL    GotIt = TRUE;
  68.         LONG    Lines,Columns;
  69.  
  70.         if(XEmulatorBase && XEM_IO)
  71.         {
  72.             if(XEmulatorBase -> lib_Version >= 4)
  73.             {
  74.                 ULONG Result = XEmulatorInfo(XEM_IO,XEMI_CONSOLE_DIMENSIONS);
  75.  
  76.                 Columns    = XEMI_EXTRACT_COLUMNS(Result);
  77.                 Lines    = XEMI_EXTRACT_LINES(Result);
  78.             }
  79.             else
  80.                 GotIt = FALSE;
  81.         }
  82.         else
  83.         {
  84.             Columns    = LastColumn + 1;
  85.             Lines    = LastLine + 1;
  86.         }
  87.  
  88.         if(GotIt && WriteRequest)
  89.         {
  90.             WriteRequest -> IOSer . io_Command    = UWCMD_TTYRESIZE;
  91.             WriteRequest -> IOSer . io_Data        = (APTR)((Columns << 16) | (Lines));
  92.             WriteRequest -> IOSer . io_Length    = (WindowWidth << 16) | (WindowHeight);
  93.  
  94.             DoIO(WriteRequest);
  95.         }
  96.     }
  97. }
  98.  
  99.     /* LoadKeyMap(STRPTR Name):
  100.      *
  101.      *    Load a keymap file from disk.
  102.      */
  103.  
  104. STATIC struct KeyMap * __regargs
  105. LoadKeyMap(STRPTR Name)
  106. {
  107.     struct KeyMapResource    *KeyMapResource;
  108.     struct KeyMap        *Map = NULL;
  109.  
  110.         /* Try to get access to the list of currently loaded
  111.          * keymap files.
  112.          */
  113.  
  114.     if(KeyMapResource = (struct KeyMapResource *)OpenResource("keymap.resource"))
  115.     {
  116.         struct KeyMapNode *Node;
  117.  
  118.             /* Try to find the keymap in the list. */
  119.  
  120.         Forbid();
  121.  
  122.         if(Node = (struct KeyMapNode *)FindName(&KeyMapResource -> kr_List,FilePart(Config -> TerminalConfig -> KeyMapFileName)))
  123.             Map = &Node -> kn_KeyMap;
  124.  
  125.         Permit();
  126.     }
  127.  
  128.         /* Still no keymap available? */
  129.  
  130.     if(!Map)
  131.     {
  132.         APTR OldPtr = ThisProcess -> pr_WindowPtr;
  133.  
  134.             /* Disable DOS requesters. */
  135.  
  136.         ThisProcess -> pr_WindowPtr = (APTR)-1;
  137.  
  138.             /* Unload the old keymap code. */
  139.  
  140.         if(KeySegment)
  141.             UnLoadSeg(KeySegment);
  142.  
  143.             /* Try to load the keymap from the
  144.              * name the user entered.
  145.              */
  146.  
  147.         if(!(KeySegment = LoadSeg(Config -> TerminalConfig -> KeyMapFileName)))
  148.         {
  149.                 /* Second try: load it from
  150.                   * the standard keymaps drawer.
  151.                   */
  152.  
  153.             strcpy(SharedBuffer,"KEYMAPS:");
  154.  
  155.             if(AddPart(SharedBuffer,FilePart(Config -> TerminalConfig -> KeyMapFileName),MAX_FILENAME_LENGTH))
  156.             {
  157.                 if(!(KeySegment = LoadSeg(SharedBuffer)))
  158.                 {
  159.                     strcpy(SharedBuffer,"Devs:Keymaps");
  160.  
  161.                     if(AddPart(SharedBuffer,FilePart(Config -> TerminalConfig -> KeyMapFileName),MAX_FILENAME_LENGTH))
  162.                         KeySegment = LoadSeg(SharedBuffer);
  163.                 }
  164.             }
  165.         }
  166.  
  167.             /* Did we get the keymap file? */
  168.  
  169.         if(KeySegment)
  170.         {
  171.             struct KeyMapNode *Node = (struct KeyMapNode *)&((ULONG *)BADDR(KeySegment))[1];
  172.  
  173.             Map = &Node -> kn_KeyMap;
  174.         }
  175.  
  176.             /* Enable DOS requesters again. */
  177.  
  178.         ThisProcess -> pr_WindowPtr = OldPtr;
  179.     }
  180.     else
  181.     {
  182.         if(KeySegment)
  183.         {
  184.             UnLoadSeg(KeySegment);
  185.  
  186.             KeySegment = NULL;
  187.         }
  188.     }
  189.  
  190.     return(Map);
  191. }
  192.  
  193.     /* DeleteOffsetTables(VOID):
  194.      *
  195.      *    Delete the line multiplication tables.
  196.      */
  197.  
  198. STATIC VOID
  199. DeleteOffsetTables(VOID)
  200. {
  201.     if(OffsetXTable)
  202.     {
  203.         FreeVecPooled(OffsetXTable);
  204.  
  205.         OffsetXTable = NULL;
  206.     }
  207.  
  208.     if(OffsetYTable)
  209.     {
  210.         FreeVecPooled(OffsetYTable);
  211.  
  212.         OffsetYTable = NULL;
  213.     }
  214. }
  215.  
  216.     /* CreateOffsetTables(VOID):
  217.      *
  218.      *    Allocate the line multiplication tables.
  219.      */
  220.  
  221. STATIC BYTE
  222. CreateOffsetTables(VOID)
  223. {
  224.     LONG    Width    = (Window -> WScreen -> Width  + TextFontWidth)  * 2 / TextFontWidth,
  225.         Height    = (Window -> WScreen -> Height + TextFontHeight) * 2 / TextFontHeight;
  226.  
  227.     DeleteOffsetTables();
  228.  
  229.     if(OffsetXTable = (LONG *)AllocVecPooled(Width * sizeof(LONG),MEMF_ANY))
  230.     {
  231.         if(OffsetYTable = (LONG *)AllocVecPooled(Height * sizeof(LONG),MEMF_ANY))
  232.         {
  233.             LONG i,j;
  234.  
  235.             for(i = j = 0 ; i < Width ; i++, j += TextFontWidth)
  236.                 OffsetXTable[i] = j;
  237.  
  238.             for(i = j = 0 ; i < Height ; i++, j += TextFontHeight)
  239.                 OffsetYTable[i] = j;
  240.  
  241.             return(TRUE);
  242.         }
  243.     }
  244.  
  245.     DeleteOffsetTables();
  246.  
  247.     return(FALSE);
  248. }
  249.  
  250.     /* CopyItemFlags(struct MenuItem *Src,struct MenuItem *Dst):
  251.      *
  252.      *    Copy single menu item flags from one menu strip
  253.      *    to another.
  254.      */
  255.  
  256. STATIC VOID __regargs
  257. CopyItemFlags(struct MenuItem *Src,struct MenuItem *Dst)
  258. {
  259.     while(Src && Dst)
  260.     {
  261.         if(Src -> SubItem)
  262.             CopyItemFlags(Src -> SubItem,Dst -> SubItem);
  263.  
  264.         Dst -> Flags = Src -> Flags;
  265.  
  266.         Src = Src -> NextItem;
  267.         Dst = Dst -> NextItem;
  268.     }
  269. }
  270.  
  271.     /* CopyMenuFlags(struct Menu *Src,struct Menu *Dst):
  272.      *
  273.      *    Copy menu flags from one menu strip to
  274.      *    another.
  275.      */
  276.  
  277. STATIC VOID __regargs
  278. CopyMenuFlags(struct Menu *Src,struct Menu *Dst)
  279. {
  280.     struct MenuItem *SrcItem,*DstItem;
  281.  
  282.     while(Src && Dst)
  283.     {
  284.         SrcItem = Src -> FirstItem;
  285.         DstItem = Dst -> FirstItem;
  286.  
  287.         while(SrcItem && DstItem)
  288.         {
  289.             CopyItemFlags(SrcItem,DstItem);
  290.  
  291.             SrcItem = SrcItem -> NextItem;
  292.             DstItem = DstItem -> NextItem;
  293.         }
  294.  
  295.         Src = Src -> NextMenu;
  296.         Dst = Dst -> NextMenu;
  297.     }
  298. }
  299.  
  300.     /* UpdateTerminalLimits():
  301.      *
  302.      *    Check the current window size and extract the
  303.      *    size and position of the usable window rectangle.
  304.      */
  305.  
  306. VOID
  307. UpdateTerminalLimits()
  308. {
  309.     WindowLeft    = Window -> BorderLeft;
  310.     WindowTop    = Window -> BorderTop;
  311.  
  312.     WindowWidth    = Window -> Width - (Window -> BorderLeft + Window -> BorderRight);
  313.     WindowHeight    = Window -> Height - (Window -> BorderTop + Window -> BorderBottom);
  314.  
  315.     if(StatusWindow)
  316.     {
  317.         StatusDisplayLeft    = StatusWindow -> BorderLeft;
  318.         StatusDisplayTop    = StatusWindow -> BorderTop;
  319.         StatusDisplayWidth    = StatusWindow -> Width - (StatusWindow -> BorderLeft + StatusWindow -> BorderRight);
  320.         StatusDisplayHeight    = StatusWindow -> Height - (StatusWindow -> BorderTop + StatusWindow -> BorderBottom);
  321.     }
  322.     else
  323.     {
  324.         if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED && !(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0]))
  325.         {
  326.             StatusDisplayLeft    = WindowLeft;
  327.             StatusDisplayTop    = Window -> Height - (Window -> BorderBottom + StatusDisplayHeight);
  328.             StatusDisplayWidth    = WindowWidth;
  329.  
  330.             WindowHeight -= StatusDisplayHeight;
  331.         }
  332.     }
  333.  
  334.     if(ChatMode && !(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0]))
  335.     {
  336.         if(CreateChatGadget())
  337.         {
  338.             UpdateChatGadget();
  339.  
  340.             WindowHeight -= (UserFontHeight + 2);
  341.  
  342.             ActivateChat(FALSE);
  343.         }
  344.     }
  345. }
  346.  
  347.     /* BuildMenu():
  348.      *
  349.      *    Create the menu strip, including quick dial menu.
  350.      */
  351.  
  352. STRPTR
  353. BuildMenu()
  354. {
  355.     struct NewMenu    *NewMenu;
  356.     struct Menu    *MenuNew;
  357.     LONG         PhoneCount = 0,
  358.              Count = 0,
  359.              i;
  360.  
  361.     BlockWindows();
  362.  
  363.         /* Clear the window menu strips. */
  364.  
  365.     if(Window)
  366.         ClearMenuStrip(Window);
  367.  
  368.     if(StatusWindow)
  369.         ClearMenuStrip(StatusWindow);
  370.  
  371.     if(FastWindow)
  372.         ClearMenuStrip(FastWindow);
  373.  
  374.         /* Count the number of menu entries in
  375.          * the base menu.
  376.          */
  377.  
  378.     while(TermMenu[Count++] . nm_Type != NM_END);
  379.  
  380.         /* Add the quick dial entries. */
  381.  
  382.     if(Phonebook)
  383.     {
  384.         for(i = 0 ; PhoneCount < DIAL_MENU_MAX && i < NumPhoneEntries ; i++)
  385.         {
  386.             if(Phonebook[i] -> Header -> QuickMenu)
  387.                 PhoneCount++;
  388.         }
  389.     }
  390.  
  391.         /* Allocate new menu prototypes. */
  392.  
  393.     if(NewMenu = (struct NewMenu *)AllocVecPooled((Count + PhoneCount) * sizeof(struct NewMenu),MEMF_ANY | MEMF_CLEAR))
  394.     {
  395.         CopyMem(TermMenu,NewMenu,Count * sizeof(struct NewMenu));
  396.  
  397.         if(PhoneCount)
  398.         {
  399.             Count--;
  400.  
  401.             PhoneCount = 0;
  402.  
  403.             FirstDialMenu = -1;
  404.  
  405.             for(i = 0 ; PhoneCount < DIAL_MENU_MAX && i < NumPhoneEntries ; i++)
  406.             {
  407.                 if(Phonebook[i] -> Header -> QuickMenu)
  408.                 {
  409.                     NewMenu[Count] . nm_Type    = NM_ITEM;
  410.                     NewMenu[Count] . nm_Label    = Phonebook[i] -> Header -> Name;
  411.                     NewMenu[Count] . nm_Flags    = CHECKIT;
  412.                     NewMenu[Count] . nm_UserData    = (APTR)(DIAL_MENU_LIMIT + i);
  413.  
  414.                     PhoneCount++;
  415.                     Count++;
  416.  
  417.                     if(FirstDialMenu == -1)
  418.                         FirstDialMenu = DIAL_MENU_LIMIT + i;
  419.                 }
  420.             }
  421.  
  422.             NewMenu[Count] . nm_Type = NM_END;
  423.         }
  424.         else
  425.             NewMenu[Count - 2] . nm_Type = NM_END;
  426.  
  427.             /* Create the menu strip. */
  428.  
  429.         if(!(MenuNew = CreateMenus(NewMenu,TAG_DONE)))
  430.         {
  431.             FreeVecPooled(NewMenu);
  432.  
  433.             goto Simple;
  434.         }
  435.  
  436.             /* Do the menu layout. */
  437.  
  438.         if(!LayoutMenus(MenuNew,VisualInfo,
  439.             GTMN_NewLookMenus,    TRUE,
  440.             GTMN_TextAttr,        &UserFont,
  441.  
  442.             AmigaGlyph ? GTMN_AmigaKey :  TAG_IGNORE, AmigaGlyph,
  443.             CheckGlyph ? GTMN_Checkmark : TAG_IGNORE, CheckGlyph,
  444.         TAG_DONE))
  445.         {
  446.             FreeVecPooled(NewMenu);
  447.  
  448.             FreeMenus(MenuNew);
  449.  
  450.             goto Simple;
  451.         }
  452.  
  453.         FreeVecPooled(NewMenu);
  454.     }
  455.     else
  456.     {
  457.             /* Create the menu strip. */
  458.  
  459. Simple:        if(!(MenuNew = CreateMenus(TermMenu,TAG_DONE)))
  460.         {
  461.             ReleaseWindows();
  462.  
  463.             return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_MENUS_TXT));
  464.         }
  465.  
  466.             /* Do the menu layout. */
  467.  
  468.         if(!LayoutMenus(MenuNew,VisualInfo,
  469.             AmigaGlyph ? GTMN_AmigaKey :  TAG_IGNORE, AmigaGlyph,
  470.             CheckGlyph ? GTMN_Checkmark : TAG_IGNORE, CheckGlyph,
  471.  
  472.             GTMN_NewLookMenus,    TRUE,
  473.             GTMN_TextAttr,        &UserFont,
  474.         TAG_DONE))
  475.         {
  476.             ReleaseWindows();
  477.  
  478.             FreeMenus(MenuNew);
  479.  
  480.             return(LocaleString(MSG_TERMINIT_FAILED_TO_LAYOUT_MENUS_TXT));
  481.         }
  482.     }
  483.  
  484.     if(Menu)
  485.     {
  486.         CopyMenuFlags(Menu,MenuNew);
  487.  
  488.         FreeMenus(Menu);
  489.     }
  490.  
  491.     Menu = MenuNew;
  492.  
  493.     if(Window)
  494.         SetMenuStrip(Window,Menu);
  495.  
  496.     if(StatusWindow)
  497.         SetMenuStrip(StatusWindow,Menu);
  498.  
  499.     if(FastWindow)
  500.         SetMenuStrip(FastWindow,Menu);
  501.  
  502.     ReleaseWindows();
  503.  
  504.     return(NULL);
  505. }
  506.  
  507.     /* Current2DefaultPalette(struct Configuration *SomeConfig):
  508.      *
  509.      *    Copy the current colour palette into the
  510.      *    default tables.
  511.      */
  512.  
  513. VOID __regargs
  514. Current2DefaultPalette(struct Configuration *SomeConfig)
  515. {
  516.     ColourTable    *Table = NULL;
  517.     UWORD        *Colour12;
  518.  
  519.     if(!SomeConfig)
  520.         SomeConfig = Config;
  521.  
  522.     switch(SomeConfig -> ScreenConfig -> ColourMode)
  523.     {
  524.         case COLOUR_EIGHT:
  525.  
  526.             if(Kick30)
  527.             {
  528.                 if(!ANSIColourTable)
  529.                     ANSIColourTable = CreateColourTable(8,ANSIColours,NULL);
  530.  
  531.                 Table = ANSIColourTable;
  532.             }
  533.  
  534.             Colour12 = ANSIColours;
  535.  
  536.             break;
  537.  
  538.         case COLOUR_SIXTEEN:
  539.  
  540.             if(Kick30)
  541.             {
  542.                 if(!EGAColourTable)
  543.                     EGAColourTable = CreateColourTable(16,EGAColours,NULL);
  544.  
  545.                 Table = EGAColourTable;
  546.             }
  547.  
  548.             Colour12 = EGAColours;
  549.  
  550.             break;
  551.  
  552.         case COLOUR_AMIGA:
  553.  
  554.             if(Kick30)
  555.             {
  556.                 if(!DefaultColourTable)
  557.                     DefaultColourTable = CreateColourTable(16,DefaultColours,NULL);
  558.  
  559.                 Table = DefaultColourTable;
  560.             }
  561.  
  562.             Colour12 = DefaultColours;
  563.  
  564.             break;
  565.  
  566.         case COLOUR_MONO:
  567.  
  568.             if(Kick30)
  569.             {
  570.                 if(!MonoColourTable)
  571.                     MonoColourTable = CreateColourTable(2,AtomicColours,NULL);
  572.  
  573.                 Table = MonoColourTable;
  574.             }
  575.  
  576.             Colour12 = AtomicColours;
  577.             break;
  578.     }
  579.  
  580.     if(Table)
  581.     {
  582.         if(SomeConfig -> ScreenConfig -> UseColours96)
  583.             Colour96xColourTable(SomeConfig -> ScreenConfig -> Colours96,Table,Table -> NumColours);
  584.         else
  585.         {
  586.             Colour12xColourTable(SomeConfig -> ScreenConfig -> Colours,Table,Table -> NumColours);
  587.  
  588.             Colour12x96(SomeConfig -> ScreenConfig -> Colours,SomeConfig -> ScreenConfig -> Colours96,16);
  589.  
  590.             SomeConfig -> ScreenConfig -> UseColours96 = TRUE;
  591.         }
  592.     }
  593.  
  594.     CopyMem(SomeConfig -> ScreenConfig -> Colours,Colour12,16 * sizeof(UWORD));
  595. }
  596.  
  597.     /* Default2CurrentPalette(struct Configuration *SomeConfig):
  598.      *
  599.      *    Copy the default palette to the current palette.
  600.      */
  601.  
  602. VOID __regargs
  603. Default2CurrentPalette(struct Configuration *SomeConfig)
  604. {
  605.     ColourTable    *Table = NULL;
  606.     UWORD        *Colour12;
  607.  
  608.     if(!SomeConfig)
  609.         SomeConfig = Config;
  610.  
  611.     switch(SomeConfig -> ScreenConfig -> ColourMode)
  612.     {
  613.         case COLOUR_EIGHT:
  614.  
  615.             Table        = ANSIColourTable;
  616.             Colour12    = ANSIColours;
  617.  
  618.             break;
  619.  
  620.         case COLOUR_SIXTEEN:
  621.  
  622.             Table        = EGAColourTable;
  623.             Colour12    = EGAColours;
  624.  
  625.             break;
  626.  
  627.         case COLOUR_AMIGA:
  628.  
  629.             Table        = DefaultColourTable;
  630.             Colour12    = DefaultColours;
  631.  
  632.             break;
  633.  
  634.         case COLOUR_MONO:
  635.  
  636.             Table        = MonoColourTable;
  637.             Colour12    = AtomicColours;
  638.             break;
  639.     }
  640.  
  641.     if(Table)
  642.     {
  643.         CopyMem(&Table -> Entry[0],SomeConfig -> ScreenConfig -> Colours96,Table -> NumColours * sizeof(ColourEntry));
  644.  
  645.         CopyMem(Colour12,SomeConfig -> ScreenConfig -> Colours,16 * sizeof(UWORD));
  646.  
  647.         SomeConfig -> ScreenConfig -> UseColours96 = TRUE;
  648.     }
  649.     else
  650.     {
  651.         CopyMem(Colour12,SomeConfig -> ScreenConfig -> Colours,16 * sizeof(UWORD));
  652.  
  653.         SomeConfig -> ScreenConfig -> UseColours96 = FALSE;
  654.     }
  655. }
  656.  
  657.     /* PaletteSetup():
  658.      *
  659.      *    Set up colour palettes.
  660.      */
  661.  
  662. VOID __regargs
  663. PaletteSetup(struct Configuration *SomeConfig)
  664. {
  665.     WORD i;
  666.  
  667.     if(!SomeConfig)
  668.         SomeConfig = Config;
  669.  
  670.     if(SomeConfig -> ScreenConfig -> UseColours96)
  671.     {
  672.         Colour96x12(SomeConfig -> ScreenConfig -> Colours96,NormalColours,16);
  673.         Colour96x12(SomeConfig -> ScreenConfig -> Colours96,SomeConfig -> ScreenConfig -> Colours,16);
  674.     }
  675.     else
  676.     {
  677.         CopyMem(SomeConfig -> ScreenConfig -> Colours,NormalColours,16 * sizeof(UWORD));
  678.  
  679.         Colour12x96(NormalColours,SomeConfig -> ScreenConfig -> Colours96,16);
  680.  
  681.         SomeConfig -> ScreenConfig -> UseColours96 = TRUE;
  682.     }
  683.  
  684.     CopyMem(NormalColours,&NormalColours[16],16 * sizeof(UWORD));
  685.     CopyMem(NormalColours,BlinkColours,32 * sizeof(UWORD));
  686.  
  687.     switch(SomeConfig -> ScreenConfig -> ColourMode)
  688.     {
  689.         case COLOUR_EIGHT:
  690.  
  691.             if(SomeConfig -> ScreenConfig -> Blinking)
  692.             {
  693.                 for(i = 0 ; i < 8 ; i++)
  694.                     BlinkColours[8 + i] = BlinkColours[0];
  695.  
  696.                 PaletteSize = 16;
  697.             }
  698.             else
  699.                 PaletteSize = 8;
  700.  
  701.             break;
  702.  
  703.         case COLOUR_SIXTEEN:
  704.  
  705.             if(GetBitMapDepth(Window -> WScreen -> RastPort . BitMap) >= 5 && SomeConfig -> ScreenConfig -> Blinking)
  706.             {
  707.                 for(i = 0 ; i < 16 ; i++)
  708.                     BlinkColours[16 + i] = BlinkColours[0];
  709.  
  710.                 PaletteSize = 32;
  711.             }
  712.             else
  713.                 PaletteSize = 16;
  714.  
  715.             break;
  716.  
  717.         case COLOUR_AMIGA:
  718.  
  719.             BlinkColours[3] = BlinkColours[0];
  720.  
  721.             PaletteSize = 4;
  722.  
  723.             break;
  724.  
  725.         case COLOUR_MONO:
  726.  
  727.             PaletteSize = 2;
  728.             break;
  729.     }
  730.  
  731.     if(Kick30)
  732.     {
  733.         if(NormalColourTable)
  734.             DeleteColourTable(NormalColourTable);
  735.  
  736.         if(BlinkColourTable)
  737.             DeleteColourTable(BlinkColourTable);
  738.  
  739.         if(NormalColourTable = CreateColourTable(PaletteSize,NULL,SomeConfig -> ScreenConfig -> Colours96))
  740.         {
  741.             if(PaletteSize == 2 || !SomeConfig -> ScreenConfig -> Blinking)
  742.                 BlinkColourTable = NULL;
  743.             else
  744.             {
  745.                 if(BlinkColourTable = CreateColourTable(PaletteSize,NULL,NULL))
  746.                 {
  747.                     switch(SomeConfig -> ScreenConfig -> ColourMode)
  748.                     {
  749.                         case COLOUR_EIGHT:
  750.  
  751.                             CopyMem(&NormalColourTable -> Entry[0],&NormalColourTable -> Entry[8],8 * sizeof(ColourEntry));
  752.                             CopyMem(&NormalColourTable -> Entry[0],&BlinkColourTable -> Entry[0],16 * sizeof(ColourEntry));
  753.  
  754.                             for(i = 1 ; i < 8 ; i++)
  755.                                 BlinkColourTable -> Entry[8 + i] = BlinkColourTable -> Entry[0];
  756.  
  757.                             break;
  758.  
  759.                         case COLOUR_SIXTEEN:
  760.  
  761.                             if(GetBitMapDepth(Window -> WScreen -> RastPort . BitMap) >= 5)
  762.                             {
  763.                                 CopyMem(&NormalColourTable -> Entry[0],&NormalColourTable -> Entry[16],16 * sizeof(ColourEntry));
  764.                                 CopyMem(&NormalColourTable -> Entry[0],&BlinkColourTable -> Entry[0],32 * sizeof(ColourEntry));
  765.  
  766.                                 for(i = 1 ; i < 16 ; i++)
  767.                                     BlinkColourTable -> Entry[16 + i] = BlinkColourTable -> Entry[0];
  768.                             }
  769.                             else
  770.                             {
  771.                                 DeleteColourTable(BlinkColourTable);
  772.  
  773.                                 BlinkColourTable = NULL;
  774.                             }
  775.  
  776.                             break;
  777.  
  778.                         case COLOUR_AMIGA:
  779.  
  780.                             CopyMem(&NormalColourTable -> Entry[0],&BlinkColourTable -> Entry[0],4 * sizeof(ColourEntry));
  781.  
  782.                             BlinkColourTable -> Entry[3] = BlinkColourTable -> Entry[0];
  783.  
  784.                             break;
  785.                     }
  786.                 }
  787.                 else
  788.                 {
  789.                     DeleteColourTable(NormalColourTable);
  790.  
  791.                     NormalColourTable = NULL;
  792.                 }
  793.             }
  794.         }
  795.     }
  796. }
  797.  
  798.     /* ResetCursorKeys(struct CursorKeys *Keys):
  799.      *
  800.      *    Reset cursor key assignments to defaults.
  801.      */
  802.  
  803. VOID __regargs
  804. ResetCursorKeys(struct CursorKeys *Keys)
  805. {
  806.     STATIC STRPTR Defaults[4] =
  807.     {
  808.         "\\e[A",
  809.         "\\e[B",
  810.         "\\e[C",
  811.         "\\e[D"
  812.     };
  813.  
  814.     WORD i,j;
  815.  
  816.     for(i = 0 ; i < 4 ; i++)
  817.     {
  818.         for(j = 0 ; j < 4 ; j++)
  819.             strcpy(Keys -> Keys[j][i],Defaults[i]);
  820.     }
  821. }
  822.  
  823.     /* ResetMacroKeys(struct MacroKeys *Keys):
  824.      *
  825.      *    Reset the macro key assignments to defaults.
  826.      */
  827.  
  828. STATIC VOID __regargs
  829. ResetMacroKeys(struct MacroKeys *Keys)
  830. {
  831.     STATIC STRPTR FunctionKeyCodes[4] =
  832.     {
  833.         "\\eOP",
  834.         "\\eOQ",
  835.         "\\eOR",
  836.         "\\eOS"
  837.     };
  838.  
  839.     WORD i;
  840.  
  841.     memset(Keys,0,sizeof(struct MacroKeys));
  842.  
  843.     for(i = 0 ; i < 4 ; i++)
  844.         strcpy(Keys -> Keys[1][i],FunctionKeyCodes[i]);
  845. }
  846.  
  847.     /* ScreenSizeStuff():
  848.      *
  849.      *    Set up the terminal screen size.
  850.      */
  851.  
  852. VOID
  853. ScreenSizeStuff()
  854. {
  855.     ObtainSemaphore(&TerminalSemaphore);
  856.  
  857.         /* Is this really the built-in emulation? */
  858.  
  859.     if(Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  860.     {
  861.         LONG    MaxColumns    = WindowWidth / TextFontWidth,
  862.             MaxLines    = WindowHeight / TextFontHeight,
  863.             Columns,
  864.             Lines;
  865.  
  866.             /* Drop the text area marker. */
  867.  
  868.         if(Marking)
  869.             DropMarker();
  870.  
  871.             /* Turn off the cursor. */
  872.  
  873.         ClearCursor();
  874.  
  875.             /* Set up the new screen width. */
  876.  
  877.         if(Config -> TerminalConfig -> NumColumns < 20)
  878.             Columns = MaxColumns;
  879.         else
  880.             Columns = Config -> TerminalConfig -> NumColumns;
  881.  
  882.             /* Set up the new screen height. */
  883.  
  884.         if(Config -> TerminalConfig -> NumLines < 20)
  885.             Lines = MaxLines;
  886.         else
  887.             Lines = Config -> TerminalConfig -> NumLines;
  888.  
  889.             /* More columns than we will be able to display? */
  890.  
  891.         if(Columns > MaxColumns)
  892.             Columns = MaxColumns;
  893.  
  894.             /* More lines than we will be able to display? */
  895.  
  896.         if(Lines > MaxLines)
  897.             Lines = MaxLines;
  898.  
  899.             /* Set up the central data. */
  900.  
  901.         LastColumn    = Columns - 1;
  902.         LastLine    = Lines - 1;
  903.         LastPixel    = MUL_X(Columns) - 1;
  904.  
  905.             /* Are we to clear the margin? */
  906.  
  907.         if(Columns < MaxColumns || Lines < MaxLines)
  908.         {
  909.                 /* Save the rendering attributes. */
  910.  
  911.             BackupRender();
  912.  
  913.                 /* Set the defaults. */
  914.  
  915.             SetAPen(RPort,BgPen = MappedPens[0][PenTable[0]]);
  916.  
  917.             SetMask(RPort,DepthMask);
  918.  
  919.                 /* Clear remaining columns. */
  920.  
  921.             if(Columns < MaxColumns)
  922.                 ScrollLineRectFill(RPort,MUL_X(LastColumn + 1),0,WindowWidth - 1,WindowHeight - 1);
  923.  
  924.                 /* Clear remaining lines. */
  925.  
  926.             if(Lines < MaxLines)
  927.                 ScrollLineRectFill(RPort,0,MUL_Y(LastLine + 1),WindowWidth - 1,WindowHeight - 1);
  928.  
  929.                 /* Restore rendering attributes. */
  930.  
  931.             BackupRender();
  932.         }
  933.  
  934.             /* Truncate illegal cursor position. */
  935.  
  936.         if(CursorY > LastLine)
  937.             CursorY = LastLine;
  938.  
  939.         ConFontScaleUpdate();
  940.  
  941.             /* Truncate illegal cursor position. */
  942.  
  943.         if(CursorX > LastColumn)
  944.             CursorX = LastColumn;
  945.  
  946.             /* Reset the cursor position. */
  947.  
  948.         if(Config -> EmulationConfig -> FontScale == SCALE_HALF)
  949.             CursorX *= 2;
  950.         else
  951.         {
  952.             if(PrivateConfig -> EmulationConfig -> FontScale == SCALE_HALF)
  953.                 CursorX /= 2;
  954.         }
  955.  
  956.             /* Fix scroll region button. */
  957.  
  958.         if(!RegionSet)
  959.             Bottom = LastLine;
  960.  
  961.             /* Turn the cursor back on. */
  962.  
  963.         DrawCursor();
  964.     }
  965.  
  966.     FixScreenSize = FALSE;
  967.  
  968.     ReleaseSemaphore(&TerminalSemaphore);
  969. }
  970.  
  971.     /* PubScreenStuff():
  972.      *
  973.      *    This part handles the public screen setup stuff.
  974.      */
  975.  
  976. VOID
  977. PubScreenStuff()
  978. {
  979.     if(Screen)
  980.     {
  981.             /* Are we to make our screen public? */
  982.  
  983.         if(Config -> ScreenConfig -> MakeScreenPublic)
  984.             PubScreenStatus(Screen,NULL);
  985.         else
  986.             PubScreenStatus(Screen,PSNF_PRIVATE);
  987.  
  988.             /* Are we to `shanghai' Workbench windows? */
  989.  
  990.         if(Config -> ScreenConfig -> ShanghaiWindows)
  991.         {
  992.             PublicModes |= SHANGHAI;
  993.  
  994.             SetPubScreenModes(PublicModes);
  995.  
  996.                 /* Make this the default public screen. */
  997.  
  998.             SetDefaultPubScreen(TermIDString);
  999.         }
  1000.         else
  1001.         {
  1002.             PublicModes &= ~SHANGHAI;
  1003.  
  1004.             if(LockPubScreen(DefaultPubScreenName))
  1005.             {
  1006.                 SetDefaultPubScreen(DefaultPubScreenName);
  1007.  
  1008.                 UnlockPubScreen(DefaultPubScreenName,NULL);
  1009.             }
  1010.             else
  1011.                 SetDefaultPubScreen(NULL);
  1012.  
  1013.             SetPubScreenModes(PublicModes);
  1014.         }
  1015.     }
  1016.  
  1017.     FixPubScreenMode = FALSE;
  1018. }
  1019.  
  1020.     /* ConfigSetup():
  1021.      *
  1022.      *    Compare the current configuration with the
  1023.      *    last backup and reset the serial device, terminal,
  1024.      *    etc. if necessary.
  1025.      */
  1026.  
  1027. VOID
  1028. ConfigSetup()
  1029. {
  1030.     BYTE RasterWasEnabled = RasterEnabled;
  1031.  
  1032.         /* Hide or show the upload queue icon. */
  1033.  
  1034.     ToggleUploadQueueIcon(Config -> TransferConfig -> HideUploadIcon);
  1035.  
  1036.         /* Take care of the end-of-line translation. */
  1037.  
  1038.     Update_CR_LF_Translation();
  1039.  
  1040.         /* First we will take a look at the configuration
  1041.          * and try to find those parts which have changed
  1042.          * and require the main screen display to be
  1043.          * reopened.
  1044.          */
  1045.  
  1046.     if(PrivateConfig -> ScreenConfig -> FontHeight != Config -> ScreenConfig -> FontHeight)
  1047.         ResetDisplay = TRUE;
  1048.  
  1049.     if((PrivateConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL) || (PrivateConfig -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL))
  1050.         ResetDisplay = TRUE;
  1051.  
  1052.     if(PrivateConfig -> ScreenConfig -> SplitStatus != Config -> ScreenConfig -> SplitStatus)
  1053.         ResetDisplay = TRUE;
  1054.  
  1055.     if(PrivateConfig -> ScreenConfig -> ShareScreen != Config -> ScreenConfig -> ShareScreen)
  1056.         ResetDisplay = TRUE;
  1057.  
  1058.     if(PrivateConfig -> ScreenConfig -> Depth != Config -> ScreenConfig -> Depth || PrivateConfig -> ScreenConfig -> OverscanType != Config -> ScreenConfig -> OverscanType)
  1059.         ResetDisplay = TRUE;
  1060.  
  1061.     if(PrivateConfig -> ScreenConfig -> DisplayWidth != Config -> ScreenConfig -> DisplayWidth || PrivateConfig -> ScreenConfig -> DisplayHeight != Config -> ScreenConfig -> DisplayHeight)
  1062.         ResetDisplay = TRUE;
  1063.  
  1064.     if(Stricmp(PrivateConfig -> ScreenConfig -> FontName,Config -> ScreenConfig -> FontName))
  1065.         ResetDisplay = TRUE;
  1066.  
  1067.     if(PrivateConfig -> TerminalConfig -> FontMode != Config -> TerminalConfig -> FontMode)
  1068.         ResetDisplay = TRUE;
  1069.  
  1070.     if(PrivateConfig -> TerminalConfig -> UseTerminalTask != Config -> TerminalConfig -> UseTerminalTask)
  1071.         ResetDisplay = TRUE;
  1072.  
  1073.     if(PrivateConfig -> TerminalConfig -> TextFontHeight != Config -> TerminalConfig -> TextFontHeight)
  1074.         ResetDisplay = TRUE;
  1075.  
  1076.     if(Stricmp(PrivateConfig -> TerminalConfig -> TextFontName,Config -> TerminalConfig -> TextFontName))
  1077.         ResetDisplay = TRUE;
  1078.  
  1079.     if(PrivateConfig -> ScreenConfig -> DisplayMode != Config -> ScreenConfig -> DisplayMode || PrivateConfig -> ScreenConfig -> ColourMode != Config -> ScreenConfig -> ColourMode)
  1080.         ResetDisplay = TRUE;
  1081.  
  1082.     if(PrivateConfig -> TerminalConfig -> IBMFontHeight != Config -> TerminalConfig -> IBMFontHeight)
  1083.         ResetDisplay = TRUE;
  1084.  
  1085.     if(Stricmp(PrivateConfig -> TerminalConfig -> IBMFontName,Config -> TerminalConfig -> IBMFontName))
  1086.         ResetDisplay = TRUE;
  1087.  
  1088.     if((PrivateConfig -> ScreenConfig -> ColourMode == Config -> ScreenConfig -> ColourMode) && (PrivateConfig -> ScreenConfig -> ColourMode == COLOUR_EIGHT || PrivateConfig -> ScreenConfig -> ColourMode == COLOUR_SIXTEEN))
  1089.     {
  1090.         if(PrivateConfig -> ScreenConfig -> Blinking != Config -> ScreenConfig -> Blinking)
  1091.             ResetDisplay = TRUE;
  1092.     }
  1093.  
  1094.     if(Kick30)
  1095.     {
  1096.         if(Config -> ScreenConfig -> UsePens != PrivateConfig -> ScreenConfig -> UsePens || memcmp(Config -> ScreenConfig -> PenArray,PrivateConfig -> ScreenConfig -> PenArray,sizeof(UWORD) * 12))
  1097.             ResetDisplay = TRUE;
  1098.     }
  1099.  
  1100.     if(Config -> ScreenConfig -> Depth != PrivateConfig -> ScreenConfig -> Depth)
  1101.         ResetDisplay = TRUE;
  1102.  
  1103.     if(PrivateConfig -> ScreenConfig -> FasterLayout != Config -> ScreenConfig -> FasterLayout)
  1104.         ResetDisplay = TRUE;
  1105.  
  1106.     if(PrivateConfig -> ScreenConfig -> StatusLine != Config -> ScreenConfig -> StatusLine)
  1107.         ResetDisplay = TRUE;
  1108.  
  1109.     if(PrivateConfig -> ScreenConfig -> TitleBar != Config -> ScreenConfig -> TitleBar)
  1110.         ResetDisplay = TRUE;
  1111.  
  1112.     if(PrivateConfig -> ScreenConfig -> UseWorkbench != Config -> ScreenConfig -> UseWorkbench)
  1113.         ResetDisplay = TRUE;
  1114.  
  1115.     if(strcmp(PrivateConfig -> ScreenConfig -> PubScreenName,Config -> ScreenConfig -> PubScreenName) && Config -> ScreenConfig -> UseWorkbench)
  1116.         ResetDisplay = TRUE;
  1117.  
  1118.     if(PrivateConfig -> EmulationConfig -> UseStandardPens != Config -> EmulationConfig -> UseStandardPens)
  1119.         ResetDisplay = TRUE;
  1120.  
  1121.     if(!Config -> EmulationConfig -> UseStandardPens && (memcmp(Config -> EmulationConfig -> Pens,PrivateConfig -> EmulationConfig -> Pens,sizeof(Config -> EmulationConfig -> Pens)) || memcmp(Config -> EmulationConfig -> Attributes,PrivateConfig -> EmulationConfig -> Attributes,sizeof(Config -> EmulationConfig -> Attributes))))
  1122.         ResetDisplay = TRUE;
  1123.  
  1124.         /* Now for the `harmless' actions which do not
  1125.          * require to change the screen or other
  1126.          * rendering data.
  1127.          */
  1128.  
  1129.     if(!ResetDisplay)
  1130.     {
  1131.         if(PrivateConfig -> TerminalConfig -> NumColumns != Config -> TerminalConfig -> NumColumns || PrivateConfig -> TerminalConfig -> NumLines != Config -> TerminalConfig -> NumLines)
  1132.         {
  1133.             if(Config -> ScreenConfig -> UseWorkbench)
  1134.             {
  1135.                 UWORD    Width,
  1136.                     Height;
  1137.  
  1138.                 if(Config -> TerminalConfig -> NumColumns < 20)
  1139.                     Width = ScreenWidth;
  1140.                 else
  1141.                     Width = Window -> BorderLeft + TextFontWidth * Config -> TerminalConfig -> NumColumns + Window -> BorderRight;
  1142.  
  1143.                 if(Config -> TerminalConfig -> NumLines < 20)
  1144.                     Height = ScreenHeight;
  1145.                 else
  1146.                     Height = Window -> BorderTop + TextFontHeight * Config -> TerminalConfig -> NumLines + Window -> BorderBottom;
  1147.  
  1148.                 ChangeWindowBox(Window,Window -> LeftEdge,Window -> TopEdge,Width,Height);
  1149.  
  1150.                 FixScreenSize = TRUE;
  1151.             }
  1152.             else
  1153.                 ResetDisplay = TRUE;
  1154.         }
  1155.     }
  1156.  
  1157.     if(PrivateConfig -> ScreenConfig -> MakeScreenPublic != Config -> ScreenConfig -> MakeScreenPublic || PrivateConfig -> ScreenConfig -> ShanghaiWindows != Config -> ScreenConfig -> ShanghaiWindows)
  1158.         PubScreenStuff();
  1159.  
  1160.     if(PrivateConfig -> ScreenConfig -> ColourMode == Config -> ScreenConfig -> ColourMode && (memcmp(PrivateConfig -> ScreenConfig -> Colours,Config -> ScreenConfig -> Colours,sizeof(UWORD) * 16) || memcmp(PrivateConfig -> ScreenConfig -> Colours96,Config -> ScreenConfig -> Colours96,sizeof(ColourEntry) * 16)))
  1161.         Current2DefaultPalette(Config);
  1162.  
  1163.         /* Are we to load a new transfer library? */
  1164.  
  1165.     if(Config -> TransferConfig -> DefaultLibrary[0] && strcmp(PrivateConfig -> TransferConfig -> DefaultLibrary,Config -> TransferConfig -> DefaultLibrary))
  1166.     {
  1167.         strcpy(LastXprLibrary,Config -> TransferConfig -> DefaultLibrary);
  1168.  
  1169.         ProtocolSetup(FALSE);
  1170.     }
  1171.  
  1172.         /* No custom keymap this time? */
  1173.  
  1174.     if(!Config -> TerminalConfig -> KeyMapFileName[0])
  1175.     {
  1176.         KeyMap = NULL;
  1177.  
  1178.         if(KeySegment)
  1179.         {
  1180.             UnLoadSeg(KeySegment);
  1181.  
  1182.             KeySegment = NULL;
  1183.         }
  1184.     }
  1185.     else
  1186.     {
  1187.             /* Check whether the keymap name has changed. */
  1188.  
  1189.         if(strcmp(PrivateConfig -> TerminalConfig -> KeyMapFileName,Config -> TerminalConfig -> KeyMapFileName))
  1190.             KeyMap = LoadKeyMap(Config -> TerminalConfig -> KeyMapFileName);
  1191.     }
  1192.  
  1193.         /* Are we to load the keyboard macro settings? */
  1194.  
  1195.     if(Config -> FileConfig -> MacroFileName[0] && Stricmp(PrivateConfig -> FileConfig -> MacroFileName,Config -> FileConfig -> MacroFileName))
  1196.     {
  1197.         if(!LoadMacros(Config -> FileConfig -> MacroFileName,MacroKeys))
  1198.             ResetMacroKeys(MacroKeys);
  1199.         else
  1200.             strcpy(LastMacros,Config -> FileConfig -> MacroFileName);
  1201.     }
  1202.  
  1203.         /* Are we to load the cursor key settings? */
  1204.  
  1205.     if(Config -> FileConfig -> CursorFileName[0] && Stricmp(PrivateConfig -> FileConfig -> CursorFileName,Config -> FileConfig -> CursorFileName))
  1206.     {
  1207.         if(!ReadIFFData(Config -> FileConfig -> CursorFileName,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  1208.             ResetCursorKeys(CursorKeys);
  1209.         else
  1210.             strcpy(LastCursorKeys,Config -> FileConfig -> CursorFileName);
  1211.     }
  1212.  
  1213.         /* Are we to load the translation tables? */
  1214.  
  1215.     if(Config -> FileConfig -> TranslationFileName[0] && Stricmp(PrivateConfig -> FileConfig -> TranslationFileName,Config -> FileConfig -> TranslationFileName))
  1216.     {
  1217.         if(SendTable)
  1218.         {
  1219.             FreeTranslationTable(SendTable);
  1220.  
  1221.             SendTable = NULL;
  1222.         }
  1223.  
  1224.         if(ReceiveTable)
  1225.         {
  1226.             FreeTranslationTable(ReceiveTable);
  1227.  
  1228.             ReceiveTable = NULL;
  1229.         }
  1230.  
  1231.         if(SendTable = AllocTranslationTable())
  1232.         {
  1233.             if(ReceiveTable = AllocTranslationTable())
  1234.             {
  1235.                 if(LoadTranslationTables(Config -> FileConfig -> TranslationFileName,SendTable,ReceiveTable))
  1236.                 {
  1237.                     strcpy(LastTranslation,Config -> FileConfig -> TranslationFileName);
  1238.  
  1239.                     if(IsStandardTable(SendTable) && IsStandardTable(ReceiveTable))
  1240.                     {
  1241.                         FreeTranslationTable(SendTable);
  1242.  
  1243.                         SendTable = NULL;
  1244.  
  1245.                         FreeTranslationTable(ReceiveTable);
  1246.  
  1247.                         ReceiveTable = NULL;
  1248.                     }
  1249.                 }
  1250.                 else
  1251.                 {
  1252.                     FreeTranslationTable(SendTable);
  1253.  
  1254.                     SendTable = NULL;
  1255.  
  1256.                     FreeTranslationTable(ReceiveTable);
  1257.  
  1258.                     ReceiveTable = NULL;
  1259.                 }
  1260.             }
  1261.             else
  1262.             {
  1263.                 FreeTranslationTable(SendTable);
  1264.  
  1265.                 SendTable = NULL;
  1266.             }
  1267.         }
  1268.     }
  1269.  
  1270.         /* Update the text sending functions. */
  1271.  
  1272.     SendSetup();
  1273.  
  1274.         /* Are we to load the fast macro settings? */
  1275.  
  1276.     if(Config -> FileConfig -> FastMacroFileName[0] && Stricmp(PrivateConfig -> FileConfig -> FastMacroFileName,Config -> FileConfig -> FastMacroFileName))
  1277.     {
  1278.         if(FastWindow)
  1279.             LT_LockWindow(FastWindow);
  1280.  
  1281.         FreeList(&FastMacroList);
  1282.  
  1283.         if(LoadFastMacros(Config -> FileConfig -> FastMacroFileName,&FastMacroList))
  1284.             strcpy(LastFastMacros,Config -> FileConfig -> FastMacroFileName);
  1285.  
  1286.         if(FastWindow)
  1287.         {
  1288.             RefreshFastWindow(TRUE);
  1289.  
  1290.             LT_UnlockWindow(FastWindow);
  1291.         }
  1292.     }
  1293.  
  1294.         /* Serial configuration needs updating? */
  1295.  
  1296.     ReconfigureSerial(Window,NULL);
  1297.  
  1298.         /* Are we to open the fast macro panel? */
  1299.  
  1300.     if(Config -> MiscConfig -> OpenFastMacroPanel)
  1301.         HadFastMacros = TRUE;
  1302.  
  1303.         /* Are we to freeze the text buffer? */
  1304.  
  1305.     if(!Config -> CaptureConfig -> BufferEnabled)
  1306.         BufferFrozen = TRUE;
  1307.  
  1308.         /* Now for the actions which require that the
  1309.          * screen stays open.
  1310.          */
  1311.  
  1312.     if(!ResetDisplay)
  1313.     {
  1314.         if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  1315.         {
  1316.             if(PrivateConfig -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL || (Config -> TerminalConfig -> EmulationFileName[0] && strcmp(PrivateConfig -> TerminalConfig -> EmulationFileName,Config -> TerminalConfig -> EmulationFileName)))
  1317.             {
  1318.                 if(!OpenEmulator(Config -> TerminalConfig -> EmulationFileName))
  1319.                 {
  1320.                     Config -> TerminalConfig -> EmulationMode = EMULATION_ANSIVT100;
  1321.  
  1322.                     ResetDisplay = TRUE;
  1323.  
  1324.                     RasterEnabled = TRUE;
  1325.  
  1326.                     MyEasyRequest(Window,LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_EMULATION_LIBRARY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Config -> TerminalConfig -> EmulationFileName);
  1327.                 }
  1328.                 else
  1329.                     RasterEnabled = FALSE;
  1330.             }
  1331.         }
  1332.         else
  1333.         {
  1334.             if(XEmulatorBase && PrivateConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  1335.             {
  1336.                 XEmulatorClearConsole(XEM_IO);
  1337.  
  1338.                 CloseEmulator();
  1339.  
  1340.                 RasterEnabled = TRUE;
  1341.  
  1342.                 ClearCursor();
  1343.  
  1344.                 Reset();
  1345.  
  1346.                 DrawCursor();
  1347.             }
  1348.             else
  1349.                 RasterEnabled = TRUE;
  1350.         }
  1351.  
  1352.         if(RasterEnabled != RasterWasEnabled)
  1353.             RasterEraseScreen(2);
  1354.  
  1355.         if(!Config -> ScreenConfig -> UseWorkbench && !SharedScreen)
  1356.         {
  1357.             PaletteSetup(Config);
  1358.  
  1359.             LoadColourTable(VPort,NormalColourTable,NormalColours,PaletteSize);
  1360.         }
  1361.  
  1362.         if(Config -> MiscConfig -> OpenFastMacroPanel && !FastWindow)
  1363.             OpenFastWindow();
  1364.  
  1365.         PubScreenStuff();
  1366.  
  1367.         if(Menu)
  1368.         {
  1369.             CheckItem(MEN_FREEZE_BUFFER,BufferFrozen);
  1370.  
  1371.             if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0])
  1372.                 OffItem(MEN_CHAT_LINE);
  1373.             else
  1374.                 CheckItem(MEN_CHAT_LINE,ChatMode);
  1375.  
  1376.             if(!XProtocolBase)
  1377.                 SetTransferMenu(FALSE);
  1378.             else
  1379.                 SetTransferMenu(TRUE);
  1380.  
  1381.             SetRasterMenu(RasterEnabled);
  1382.         }
  1383.  
  1384.         Blocking = FALSE;
  1385.     }
  1386.     else
  1387.     {
  1388.             /* Are we no longer to use the external emulator? */
  1389.  
  1390.         if(Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  1391.         {
  1392.             if(XEmulatorBase && PrivateConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  1393.             {
  1394.                 XEmulatorClearConsole(XEM_IO);
  1395.  
  1396.                 CloseEmulator();
  1397.             }
  1398.         }
  1399.  
  1400.         RasterEnabled = TRUE;
  1401.     }
  1402.  
  1403.         /* Change the task priority. */
  1404.  
  1405.     SetTaskPri(ThisProcess,(LONG)Config -> MiscConfig -> Priority);
  1406.  
  1407.     ConOutputUpdate();
  1408.  
  1409.     ConFontScaleUpdate();
  1410.  
  1411.     ConProcessUpdate();
  1412.  
  1413.         /* Reset the scanner. */
  1414.  
  1415.     FlowInit(TRUE);
  1416. }
  1417.  
  1418.     /* DisplayReset():
  1419.      *
  1420.      *    Reset the entire display if necessary.
  1421.      */
  1422.  
  1423. BYTE
  1424. DisplayReset()
  1425. {
  1426.     UBYTE    *Result;
  1427.     BYTE     Success = TRUE;
  1428.  
  1429.         /* Delete the display (if possible).
  1430.          * This will go wrong if there
  1431.          * are any visitor windows on our
  1432.          * screen.
  1433.          */
  1434.  
  1435.     if(DeleteDisplay())
  1436.     {
  1437.         if(Result = CreateDisplay(FALSE))
  1438.         {
  1439.             DeleteDisplay();
  1440.  
  1441.             MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Result);
  1442.  
  1443.             Success = FALSE;
  1444.         }
  1445.         else
  1446.         {
  1447.             BumpWindow(Window);
  1448.  
  1449.             PubScreenStuff();
  1450.  
  1451.             DisplayReopened = TRUE;
  1452.         }
  1453.     }
  1454.     else
  1455.     {
  1456.         SaveConfig(PrivateConfig,Config);
  1457.  
  1458.         BlockWindows();
  1459.  
  1460.         MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_TERMMAIN_CANNOT_CLOSE_SCREEN_YET_TXT));
  1461.  
  1462.         ReleaseWindows();
  1463.  
  1464.         Success = TRUE;
  1465.     }
  1466.  
  1467.     ResetDisplay = FALSE;
  1468.  
  1469.         /* Prepare for the worst case... */
  1470.  
  1471.     if(Success)
  1472.         Apocalypse = FALSE;
  1473.     else
  1474.         MainTerminated = Apocalypse = TRUE;
  1475.  
  1476.     return(Success);
  1477. }
  1478.  
  1479.     /* DeleteDisplay():
  1480.      *
  1481.      *    Free all resources associated with the terminal
  1482.      *    display (tasks, interrupts, screen, window, etc.).
  1483.      */
  1484.  
  1485. BYTE
  1486. DeleteDisplay()
  1487. {
  1488.     if(Screen)
  1489.     {
  1490.         struct List        *PubScreenList;
  1491.         struct PubScreenNode    *ScreenNode;
  1492.  
  1493.         PubScreenList = LockPubScreenList();
  1494.  
  1495.         for(ScreenNode = (struct PubScreenNode *)PubScreenList -> lh_Head ; ScreenNode -> psn_Node . ln_Succ ; ScreenNode = (struct PubScreenNode *)ScreenNode -> psn_Node . ln_Succ)
  1496.         {
  1497.             if(ScreenNode -> psn_Screen == Screen)
  1498.                 break;
  1499.         }
  1500.  
  1501.         if(ScreenNode && ScreenNode -> psn_Node . ln_Succ)
  1502.         {
  1503.             if(ScreenNode -> psn_VisitorCount)
  1504.             {
  1505.                 UnlockPubScreenList();
  1506.  
  1507.                 return(FALSE);
  1508.             }
  1509.             else
  1510.             {
  1511.                 Forbid();
  1512.  
  1513.                 UnlockPubScreenList();
  1514.  
  1515.                 PubScreenStatus(Screen,PSNF_PRIVATE);
  1516.  
  1517.                 Permit();
  1518.             }
  1519.         }
  1520.         else
  1521.             UnlockPubScreenList();
  1522.     }
  1523.  
  1524.     if(SharedScreen)
  1525.     {
  1526.         struct List        *PubScreenList;
  1527.         struct PubScreenNode    *ScreenNode;
  1528.  
  1529.         PubScreenList = LockPubScreenList();
  1530.  
  1531.         for(ScreenNode = (struct PubScreenNode *)PubScreenList -> lh_Head ; ScreenNode -> psn_Node . ln_Succ ; ScreenNode = (struct PubScreenNode *)ScreenNode -> psn_Node . ln_Succ)
  1532.         {
  1533.             if(ScreenNode -> psn_Screen == SharedScreen)
  1534.                 break;
  1535.         }
  1536.  
  1537.         if(ScreenNode && ScreenNode -> psn_Node . ln_Succ)
  1538.         {
  1539.             if(ScreenNode -> psn_VisitorCount)
  1540.             {
  1541.                 UnlockPubScreenList();
  1542.  
  1543.                 return(FALSE);
  1544.             }
  1545.             else
  1546.             {
  1547.                 Forbid();
  1548.  
  1549.                 UnlockPubScreenList();
  1550.  
  1551.                 PubScreenStatus(SharedScreen,PSNF_PRIVATE);
  1552.  
  1553.                 Permit();
  1554.             }
  1555.         }
  1556.         else
  1557.             UnlockPubScreenList();
  1558.     }
  1559.  
  1560.     GuideCleanup();
  1561.  
  1562.     DeleteLED();
  1563.  
  1564.     CloseQueueWindow();
  1565.  
  1566.     if(StatusProcess)
  1567.     {
  1568.         Forbid();
  1569.  
  1570.         Signal(StatusProcess,SIG_KILL);
  1571.  
  1572.         ClrSignal(SIG_HANDSHAKE);
  1573.  
  1574.         Wait(SIG_HANDSHAKE);
  1575.  
  1576.         Permit();
  1577.  
  1578.         StatusProcess = NULL;
  1579.     }
  1580.  
  1581.     if(Marking)
  1582.         FreeMarker();
  1583.  
  1584.     FirstClick    = TRUE;
  1585.     HoldClick    = FALSE;
  1586.  
  1587.     CloseInfoWindow();
  1588.  
  1589.     DeleteReview();
  1590.  
  1591.     DeleteEmulationProcess();
  1592.  
  1593.     if(Config)
  1594.     {
  1595.         if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && XEmulatorBase)
  1596.             CloseEmulator();
  1597.     }
  1598.  
  1599.     DeleteRaster();
  1600.  
  1601.     DeleteScale();
  1602.  
  1603.     if(TabStops)
  1604.     {
  1605.         FreeVecPooled(TabStops);
  1606.  
  1607.         TabStops = NULL;
  1608.     }
  1609.  
  1610.     if(ScrollLines)
  1611.     {
  1612.         FreeVecPooled(ScrollLines);
  1613.  
  1614.         ScrollLines = NULL;
  1615.     }
  1616.  
  1617.     if(Screen)
  1618.         ScreenToBack(Screen);
  1619.  
  1620.     if(FastWindow)
  1621.     {
  1622.         HadFastMacros = TRUE;
  1623.  
  1624.         CloseFastWindow();
  1625.     }
  1626.     else
  1627.         HadFastMacros = FALSE;
  1628.  
  1629.         /* Clean up the menu glyphs. */
  1630.  
  1631.     DisposeObject(AmigaGlyph);
  1632.  
  1633.     AmigaGlyph = NULL;
  1634.  
  1635.     DisposeObject(CheckGlyph);
  1636.  
  1637.     CheckGlyph = NULL;
  1638.  
  1639.     if(StatusWindow)
  1640.     {
  1641.         ClearMenuStrip(StatusWindow);
  1642.         CloseWindowSafely(StatusWindow);
  1643.  
  1644.         StatusWindow = NULL;
  1645.     }
  1646.  
  1647.     if(DefaultPubScreen)
  1648.     {
  1649.         UnlockPubScreen(NULL,DefaultPubScreen);
  1650.  
  1651.         DefaultPubScreen = NULL;
  1652.     }
  1653.  
  1654.         /* Remove AppWindow link. */
  1655.  
  1656.     if(WorkbenchWindow)
  1657.     {
  1658.         RemoveAppWindow(WorkbenchWindow);
  1659.  
  1660.         WorkbenchWindow = NULL;
  1661.     }
  1662.  
  1663.         /* Remove AppWindow port and any pending messages. */
  1664.  
  1665.     if(WorkbenchPort)
  1666.     {
  1667.         struct Message *Message;
  1668.  
  1669.         while(Message = GetMsg(WorkbenchPort))
  1670.             ReplyMsg(Message);
  1671.  
  1672.         DeleteMsgPort(WorkbenchPort);
  1673.  
  1674.         WorkbenchPort = NULL;
  1675.     }
  1676.  
  1677.     if(DrawInfo)
  1678.     {
  1679.             /* Release the rendering pens. */
  1680.  
  1681.         FreeScreenDrawInfo(Window -> WScreen,DrawInfo);
  1682.  
  1683.         DrawInfo = NULL;
  1684.     }
  1685.  
  1686.     HideChatGadget();
  1687.  
  1688.     if(Window)
  1689.     {
  1690.         if(!Screen)
  1691.             PutWindowInfo(WINDOW_MAIN,Window -> LeftEdge,Window -> TopEdge,Window -> Width,Window -> Height);
  1692.  
  1693.         if(AllocatedPens && Kick30)
  1694.         {
  1695.             WORD i;
  1696.  
  1697.             ObtainSemaphore(&TerminalSemaphore);
  1698.  
  1699.                 /* Erase the window contents. We will
  1700.                  * want to release any pens we have
  1701.                  * allocated and want to avoid nasty
  1702.                  * flashing and flickering.
  1703.                  */
  1704.  
  1705.             SetAPen(RPort,0);
  1706.  
  1707.             RectFill(RPort,WindowLeft,WindowTop,WindowLeft + WindowWidth - 1,WindowTop + WindowHeight - 1);
  1708.  
  1709.                 /* Release any pens we have allocated. */
  1710.  
  1711.             for(i = 0 ; i < 16 ; i++)
  1712.             {
  1713.                 if(MappedPens[1][i])
  1714.                 {
  1715.                     ReleasePen(VPort -> ColorMap,MappedPens[0][i]);
  1716.  
  1717.                     MappedPens[0][i] = i;
  1718.                     MappedPens[1][i] = FALSE;
  1719.                 }
  1720.             }
  1721.  
  1722.             AllocatedPens = FALSE;
  1723.  
  1724.             ReleaseSemaphore(&TerminalSemaphore);
  1725.         }
  1726.  
  1727.         if(ClipRegion)
  1728.         {
  1729.             InstallClipRegion(Window -> WLayer,OldRegion);
  1730.  
  1731.             DisposeRegion(ClipRegion);
  1732.  
  1733.             ClipRegion = NULL;
  1734.         }
  1735.  
  1736.         ClearMenuStrip(Window);
  1737.  
  1738.         ThisProcess -> pr_WindowPtr = OldWindowPtr;
  1739.  
  1740.         PopWindow();
  1741.  
  1742.         if(TermPort)
  1743.             TermPort -> TopWindow = NULL;
  1744.  
  1745.         LT_DeleteWindowLock(Window);
  1746.  
  1747.         CloseWindow(Window);
  1748.  
  1749.         Window = NULL;
  1750.     }
  1751.  
  1752.     if(Menu)
  1753.     {
  1754.         FreeMenus(Menu);
  1755.  
  1756.         Menu = NULL;
  1757.     }
  1758.  
  1759.     if(VisualInfo)
  1760.     {
  1761.         FreeVisualInfo(VisualInfo);
  1762.  
  1763.         VisualInfo = NULL;
  1764.     }
  1765.  
  1766.     DeletePacketWindow(FALSE);
  1767.  
  1768.     if(UserTextFont)
  1769.     {
  1770.         CloseFont(UserTextFont);
  1771.  
  1772.         UserTextFont = NULL;
  1773.     }
  1774.  
  1775.         /* Before we can close screen we will have to
  1776.          * make sure that it is no longer the default
  1777.          * public screen.
  1778.          */
  1779.  
  1780.     if(Config)
  1781.     {
  1782.         if(Config -> ScreenConfig -> ShanghaiWindows)
  1783.         {
  1784.             if(LockPubScreen(DefaultPubScreenName))
  1785.             {
  1786.                 SetDefaultPubScreen(DefaultPubScreenName);
  1787.  
  1788.                 UnlockPubScreen(DefaultPubScreenName,NULL);
  1789.             }
  1790.             else
  1791.                 SetDefaultPubScreen(NULL);
  1792.         }
  1793.     }
  1794.  
  1795.     if(Screen)
  1796.     {
  1797.         CloseScreen(Screen);
  1798.  
  1799.         Screen = NULL;
  1800.     }
  1801.  
  1802.     if(SharedScreen)
  1803.     {
  1804.         CloseScreen(SharedScreen);
  1805.  
  1806.         SharedScreen = NULL;
  1807.     }
  1808.  
  1809.     if(GFX)
  1810.     {
  1811.         CloseFont(GFX);
  1812.  
  1813.         GFX = NULL;
  1814.     }
  1815.  
  1816.     if(TextFont)
  1817.     {
  1818.         CloseFont(TextFont);
  1819.  
  1820.         TextFont = NULL;
  1821.     }
  1822.  
  1823.     return(TRUE);
  1824. }
  1825.  
  1826. STATIC VOID __regargs
  1827. StatusSizeSetup(struct Screen *Screen,LONG *StatusWidth,LONG *StatusHeight)
  1828. {
  1829.     SZ_SizeSetup(Screen,&UserFont);
  1830.  
  1831.     if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0] && Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED && !Config -> ScreenConfig -> SplitStatus)
  1832.     {
  1833.         *StatusHeight = 0;
  1834.  
  1835.         return;
  1836.     }
  1837.  
  1838.     if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED)
  1839.     {
  1840.         if(Config -> ScreenConfig -> StatusLine == STATUSLINE_COMPRESSED)
  1841.         {
  1842.             *StatusWidth    = 80 * UserFontWidth;
  1843.             *StatusHeight    = UserFontHeight;
  1844.  
  1845.             if(Config -> ScreenConfig -> SplitStatus)
  1846.             {
  1847.                 *StatusWidth    += 2;
  1848.                 *StatusHeight    += 2;
  1849.             }
  1850.         }
  1851.         else
  1852.         {
  1853.             LONG    i,Len,Max;
  1854.             UWORD    ColumnLeft[4],
  1855.                 ColumnWidth[4];
  1856.  
  1857.             *StatusWidth    = 0;
  1858.             *StatusHeight    = SZ_BoxHeight(2);
  1859.  
  1860.             ColumnLeft[0] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_STATUS_TXT,MSG_TERMSTATUSDISPLAY_FONT_TXT,-1);
  1861.             ColumnLeft[1] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_PROTOCOL_TXT,MSG_TERMSTATUSDISPLAY_TERMINAL_TXT,-1);
  1862.             ColumnLeft[2] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_BAUDRATE_TXT,MSG_TERMSTATUSDISPLAY_PARAMETERS_TXT,-1);
  1863.             ColumnLeft[3] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_TIME_TXT,MSG_TERMSTATUSDISPLAY_ONLINE_TXT,-1);
  1864.  
  1865.             Max = 0;
  1866.  
  1867.             for(i = MSG_TERMAUX_READY_TXT ; i <= MSG_TERMAUX_HANG_UP_TXT ; i++)
  1868.             {
  1869.                 if((Len = SZ_BoxWidth(strlen(LocaleString(i)))) > Max)
  1870.                     Max = Len;
  1871.             }
  1872.  
  1873.             for(i = MSG_TERMSTATUSDISPLAY_FROZEN_TXT ; i <= MSG_TERMSTATUSDISPLAY_RECORDING_TXT ; i++)
  1874.             {
  1875.                 if((Len = SZ_BoxWidth(strlen(LocaleString(i)))) > Max)
  1876.                     Max = Len;
  1877.             }
  1878.  
  1879.             ColumnWidth[0] = Max;
  1880.  
  1881.             Max = SZ_BoxWidth(12);
  1882.  
  1883.             for(i = MSG_TERMAUX_ANSI_VT102_TXT ; i <= MSG_TERMAUX_HEX_TXT ; i++)
  1884.             {
  1885.                 if((Len = SZ_BoxWidth(strlen(LocaleString(i)))) > Max)
  1886.                     Max = Len;
  1887.             }
  1888.  
  1889.             ColumnWidth[1] = Max;
  1890.  
  1891.             Max = SZ_BoxWidth(10);
  1892.  
  1893.             for(i = MSG_TERMAUX_NONE_TXT ; i <= MSG_TERMAUX_SPACE_TXT ; i++)
  1894.             {
  1895.                 if((Len = SZ_BoxWidth(4 + strlen(LocaleString(i)))) > Max)
  1896.                     Max = Len;
  1897.             }
  1898.  
  1899.             ColumnWidth[2] = Max;
  1900.  
  1901.             ColumnWidth[3] = SZ_BoxWidth(8);
  1902.  
  1903.             for(i = 0 ; i < 4 ; i++)
  1904.                 *StatusWidth += ColumnWidth[i] + ColumnLeft[i];
  1905.  
  1906.             *StatusWidth += 3 * InterWidth;
  1907.  
  1908.             if(!Config -> ScreenConfig -> SplitStatus)
  1909.             {
  1910.                 *StatusWidth    += 2;
  1911.                 *StatusHeight    += 4;
  1912.             }
  1913.             else
  1914.             {
  1915.                 *StatusWidth    += 2;
  1916.                 *StatusHeight    += 2;
  1917.             }
  1918.         }
  1919.     }
  1920.     else
  1921.         *StatusHeight = 0;
  1922. }
  1923.  
  1924.     /* CreateDisplay(BYTE FirstSetup):
  1925.      *
  1926.      *    Open the display and allocate associated data.
  1927.      */
  1928.  
  1929. STRPTR __regargs
  1930. CreateDisplay(BYTE FirstSetup)
  1931. {
  1932.     UWORD            Count = 0,i;
  1933.     LONG            ErrorCode,Top,Height;
  1934.     ULONG            TagArray[9];
  1935.     struct Rectangle    DisplayClip;
  1936.     BYTE            OpenFailed = FALSE,
  1937.                 RealDepth;
  1938.     STRPTR            Error;
  1939.     ULONG            X_DPI,Y_DPI;
  1940.     UWORD            PenArray[16];
  1941.     LONG            StatusWidth,
  1942.                 StatusHeight;
  1943.  
  1944.     BlockNestCount = 0;
  1945.  
  1946.     WeAreBlocking = FALSE;
  1947.  
  1948.     SetQueueDiscard(SpecialQueue,FALSE);
  1949.  
  1950.     TagDPI[0] . ti_Tag = TAG_DONE;
  1951.  
  1952.         /* Don't permit weird settings. */
  1953.  
  1954.     if(!Config -> ScreenConfig -> StatusLine || (!Config -> ScreenConfig -> ShareScreen && !Config -> ScreenConfig -> UseWorkbench))
  1955.         Config -> ScreenConfig -> SplitStatus = FALSE;
  1956.  
  1957.     if(Config -> ScreenConfig -> UseWorkbench || Config -> ScreenConfig -> ShareScreen)
  1958.     {
  1959.         STRPTR ScreenName = NULL;
  1960.  
  1961.         if(Config -> ScreenConfig -> PubScreenName[0])
  1962.         {
  1963.             struct Screen *SomeScreen;
  1964.  
  1965.             if(SomeScreen = LockPubScreen(Config -> ScreenConfig -> PubScreenName))
  1966.             {
  1967.                 UnlockPubScreen(NULL,SomeScreen);
  1968.  
  1969.                 ScreenName = Config -> ScreenConfig -> PubScreenName;
  1970.             }
  1971.         }
  1972.  
  1973.         if(!(DefaultPubScreen = LockPubScreen(ScreenName)))
  1974.             return(LocaleString(MSG_TERMINIT_FAILED_TO_GET_DEFAULT_PUBLIC_SCREEN_TXT));
  1975.         else
  1976.         {
  1977.             GetDPI(GetVPModeID(&DefaultPubScreen -> ViewPort),&X_DPI,&Y_DPI);
  1978.  
  1979.                 /* gadtools.library v37 objects don't look too pretty
  1980.                  * with a proportional-spaced font.
  1981.                  */
  1982.  
  1983. /*            if(!(DefaultPubScreen -> Font -> ta_Flags & FPF_PROPORTIONAL) || Kick30)*/
  1984.  
  1985.             if(TRUE)
  1986.             {
  1987.                 strcpy(UserFontName,DefaultPubScreen -> Font -> ta_Name);
  1988.  
  1989.                 UserFont . tta_Name    = UserFontName;
  1990.                 UserFont . tta_YSize    = DefaultPubScreen -> Font -> ta_YSize;
  1991.                 UserFont . tta_Style    = DefaultPubScreen -> Font -> ta_Style;
  1992.                 UserFont . tta_Flags    = DefaultPubScreen -> Font -> ta_Flags;
  1993.             }
  1994.             else
  1995.             {
  1996.                 UnlockPubScreen(NULL,DefaultPubScreen);
  1997.  
  1998.                 DefaultPubScreen = NULL;
  1999.  
  2000.                 Config -> ScreenConfig -> UseWorkbench = FALSE;
  2001.             }
  2002.         }
  2003.     }
  2004.  
  2005.     if(!Config -> ScreenConfig -> UseWorkbench)
  2006.     {
  2007.         GetDPI(Config -> ScreenConfig -> DisplayMode,&X_DPI,&Y_DPI);
  2008.  
  2009.         strcpy(UserFontName,Config -> ScreenConfig -> FontName);
  2010.  
  2011.         UserFont . tta_Name    = UserFontName;
  2012.         UserFont . tta_YSize    = Config -> ScreenConfig -> FontHeight;
  2013.         UserFont . tta_Style    = FS_NORMAL | FSF_TAGGED;
  2014.         UserFont . tta_Flags    = FPF_DESIGNED;
  2015.         UserFont . tta_Tags    = TagDPI;
  2016.  
  2017.         TagDPI[0] . ti_Tag     = TA_DeviceDPI;
  2018.         TagDPI[0] . ti_Data     = (X_DPI << 16) | Y_DPI;
  2019.         TagDPI[1] . ti_Tag     = TAG_DONE;
  2020.     }
  2021.  
  2022.     if(!(UserTextFont = OpenDiskFont(&UserFont)))
  2023.     {
  2024.         if(Config -> ScreenConfig -> UseWorkbench)
  2025.             return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_FONT_TXT));
  2026.         else
  2027.         {
  2028.             strcpy(Config -> ScreenConfig -> FontName,    "topaz.font");
  2029.             strcpy(UserFontName,                "topaz.font");
  2030.  
  2031.             Config -> ScreenConfig -> FontHeight = 8;
  2032.  
  2033.             UserFont . tta_YSize    = Config -> ScreenConfig -> FontHeight;
  2034.             UserFont . tta_Style    = FS_NORMAL;
  2035.             UserFont . tta_Flags    = FPF_DESIGNED | FPF_ROMFONT;
  2036.  
  2037.             if(!(UserTextFont = OpenFont(&UserFont)))
  2038.                 return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_FONT_TXT));
  2039.         }
  2040.     }
  2041.  
  2042. Reopen:    if(Config -> TerminalConfig -> FontMode != FONT_STANDARD)
  2043.     {
  2044.         strcpy(TextFontName,Config -> TerminalConfig -> IBMFontName);
  2045.  
  2046.         TextAttr . tta_YSize = Config -> TerminalConfig -> IBMFontHeight;
  2047.     }
  2048.     else
  2049.     {
  2050.         strcpy(TextFontName,Config -> TerminalConfig -> TextFontName);
  2051.  
  2052.         TextAttr . tta_YSize = Config -> TerminalConfig -> TextFontHeight;
  2053.     }
  2054.  
  2055.     TextAttr . tta_Name    = TextFontName;
  2056.     TextAttr . tta_Style    = FS_NORMAL | FSF_TAGGED;
  2057.     TextAttr . tta_Flags    = FPF_DESIGNED;
  2058.     TextAttr . tta_Tags    = TagDPI;
  2059.  
  2060.     if(!(TextFont = OpenDiskFont(&TextAttr)))
  2061.     {
  2062.         if(Config -> TerminalConfig -> FontMode != FONT_STANDARD)
  2063.         {
  2064.             Config -> TerminalConfig -> FontMode = FONT_STANDARD;
  2065.  
  2066.             goto Reopen;
  2067.         }
  2068.  
  2069.         strcpy(Config -> TerminalConfig -> TextFontName,    "topaz.font");
  2070.         strcpy(TextFontName,                    "topaz.font");
  2071.  
  2072.         Config -> TerminalConfig -> TextFontHeight = 8;
  2073.  
  2074.         TextAttr . tta_YSize    = Config -> TerminalConfig -> TextFontHeight;
  2075.         TextAttr . tta_Style    = FS_NORMAL;
  2076.         TextAttr . tta_Flags    = FPF_DESIGNED | FPF_ROMFONT;
  2077.         TextAttr . tta_Tags    = NULL;
  2078.  
  2079.         if(!(TextFont = OpenFont(&TextAttr)))
  2080.             return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_TEXT_TXT));
  2081.     }
  2082.  
  2083.     TextFontHeight    = TextFont -> tf_YSize;
  2084.     TextFontWidth    = TextFont -> tf_XSize;
  2085.     TextFontBase    = TextFont -> tf_Baseline;
  2086.  
  2087.         /* Determine extra font box width for slanted/boldface glyphs. */
  2088.  
  2089.     FontRightExtend    = MAX(TextFont -> tf_XSize / 2,TextFont -> tf_BoldSmear);
  2090.  
  2091.     CurrentFont = TextFont;
  2092.  
  2093.     GFXFont . ta_YSize = TextFontHeight;
  2094.  
  2095.     if(GFX = (struct TextFont *)OpenDiskFont(&GFXFont))
  2096.     {
  2097.         if(GFX -> tf_XSize != TextFont -> tf_XSize || GFX -> tf_YSize != TextFont -> tf_YSize)
  2098.         {
  2099.             CloseFont(GFX);
  2100.  
  2101.             GFX = NULL;
  2102.         }
  2103.     }
  2104.  
  2105.     UserFontHeight    = UserTextFont -> tf_YSize;
  2106.     UserFontWidth    = UserTextFont -> tf_XSize;
  2107.     UserFontBase    = UserTextFont -> tf_Baseline;
  2108.  
  2109.     if(Config -> ScreenConfig -> UseWorkbench || Config -> ScreenConfig -> ShareScreen)
  2110.     {
  2111.         struct TagItem     SomeTags[7];
  2112.         LONG         FullWidth,
  2113.                  Height,Width,
  2114.                  Index = 0;
  2115.         struct Screen    *LocalScreen = DefaultPubScreen;
  2116.  
  2117.         if(Config -> ScreenConfig -> ShareScreen && !Config -> ScreenConfig -> UseWorkbench)
  2118.         {
  2119.             struct DimensionInfo DimensionInfo;
  2120.  
  2121.             if(ModeNotAvailable(Config -> ScreenConfig -> DisplayMode))
  2122.             {
  2123.                 Config -> ScreenConfig -> DisplayMode = GetVPModeID(&DefaultPubScreen -> ViewPort);
  2124.  
  2125.                 if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2126.                 {
  2127.                     LONG    Width    = DimensionInfo . TxtOScan . MaxX - DimensionInfo . TxtOScan . MinX + 1,
  2128.                         Height    = DimensionInfo . TxtOScan . MaxY - DimensionInfo . TxtOScan . MinY + 1;
  2129.  
  2130.                     if(Width != Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayWidth)
  2131.                         Config -> ScreenConfig -> DisplayWidth = Width;
  2132.  
  2133.                     if(Height != Config -> ScreenConfig -> DisplayHeight && Config -> ScreenConfig -> DisplayHeight)
  2134.                         Config -> ScreenConfig -> DisplayHeight = Height;
  2135.                 }
  2136.             }
  2137.  
  2138.             if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2139.             {
  2140.                 LONG    Depth,ScreenWidth,ScreenHeight;
  2141.                 UWORD    Pens = (UWORD)~0;
  2142.  
  2143.                 if(Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayHeight && AslBase -> lib_Version >= 38)
  2144.                 {
  2145.                     ScreenWidth    = Config -> ScreenConfig -> DisplayWidth;
  2146.                     ScreenHeight    = Config -> ScreenConfig -> DisplayHeight;
  2147.                 }
  2148.                 else
  2149.                 {
  2150.                     ScreenWidth    = 0;
  2151.                     ScreenHeight    = 0;
  2152.                 }
  2153.  
  2154.                 switch(Config -> ScreenConfig -> ColourMode)
  2155.                 {
  2156.                     case COLOUR_EIGHT:
  2157.  
  2158.                         Depth = 3;
  2159.                         break;
  2160.  
  2161.                     case COLOUR_SIXTEEN:
  2162.  
  2163.                         Depth = 4;
  2164.                         break;
  2165.  
  2166.                     case COLOUR_AMIGA:
  2167.  
  2168.                         Depth = 2;
  2169.                         break;
  2170.  
  2171.                     default:
  2172.  
  2173.                         Depth = 1;
  2174.                         break;
  2175.                 }
  2176.  
  2177.                 if(Depth > DimensionInfo . MaxDepth)
  2178.                     Depth = DimensionInfo . MaxDepth;
  2179.  
  2180.                 if(!Kick30 && Depth > 2)
  2181.                     Depth = 2;
  2182.  
  2183.                 if(Config -> ScreenConfig -> Depth && Config -> ScreenConfig -> Depth <= DimensionInfo . MaxDepth)
  2184.                     Depth = Config -> ScreenConfig -> Depth;
  2185.  
  2186. #ifdef _M68030
  2187.                 SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"'030 ",TermDate,TermIDString);
  2188. #else
  2189.                 SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"",TermDate,TermIDString);
  2190. #endif    /* _M68030 */
  2191.                 if(SharedScreen = OpenScreenTags(NULL,
  2192.                     ScreenWidth  ? SA_Width  : TAG_IGNORE,    ScreenWidth,
  2193.                     ScreenHeight ? SA_Height : TAG_IGNORE,    ScreenHeight,
  2194.  
  2195.                     SA_Title,    ScreenTitle,
  2196.                     SA_Depth,    Depth,
  2197.                     SA_Pens,    &Pens,
  2198.                     SA_Overscan,    AslBase -> lib_Version >= 38 ? Config -> ScreenConfig -> OverscanType : OSCAN_TEXT,
  2199.                     SA_DisplayID,    Config -> ScreenConfig -> DisplayMode,
  2200.                     SA_Font,    &UserFont,
  2201.                     SA_AutoScroll,    TRUE,
  2202.                     SA_ShowTitle,    Config -> ScreenConfig -> TitleBar,
  2203.                     SA_PubName,    TermIDString,
  2204.                     SA_Interleaved,    Config -> ScreenConfig -> FasterLayout,
  2205.                     SA_SharePens,    TRUE,
  2206.                 TAG_DONE))
  2207.                 {
  2208.                     LocalScreen = SharedScreen;
  2209.  
  2210.                     if(DefaultPubScreen)
  2211.                     {
  2212.                         UnlockPubScreen(NULL,DefaultPubScreen);
  2213.  
  2214.                         DefaultPubScreen = NULL;
  2215.                     }
  2216.  
  2217.                     if(Config -> ScreenConfig -> MakeScreenPublic)
  2218.                         PubScreenStatus(LocalScreen,NULL);
  2219.                     else
  2220.                         PubScreenStatus(LocalScreen,PSNF_PRIVATE);
  2221.                 }
  2222.             }
  2223.         }
  2224.  
  2225.         if(!SharedScreen)
  2226.         {
  2227. #ifdef _M68030
  2228.             SPrintf(ScreenTitle,"%s '030 (%s)",TermName,TermDate);
  2229. #else
  2230.             SPrintf(ScreenTitle,"%s (%s)",TermName,TermDate);
  2231. #endif    /* _M68030 */
  2232.  
  2233.         }
  2234.  
  2235.         StatusSizeSetup(LocalScreen,&StatusWidth,&StatusHeight);
  2236.  
  2237.         if(GetBitMapDepth(LocalScreen -> RastPort . BitMap) == 1 || Config -> ScreenConfig -> FasterLayout)
  2238.             UseMasking = FALSE;
  2239.         else
  2240.         {
  2241.             if(Kick30)
  2242.             {
  2243.                 if(GetBitMapAttr(LocalScreen -> RastPort . BitMap,BMA_FLAGS) & BMF_INTERLEAVED)
  2244.                     UseMasking = FALSE;
  2245.                 else
  2246.                     UseMasking = TRUE;
  2247.             }
  2248.             else
  2249.                 UseMasking = TRUE;
  2250.         }
  2251.  
  2252.         VPort = &LocalScreen -> ViewPort;
  2253.  
  2254.             /* Get the current display dimensions. */
  2255.  
  2256.         if(VPort -> ColorMap -> cm_vpe)
  2257.         {
  2258.             struct ViewPortExtra *Extra;
  2259.  
  2260.             Extra = VPort -> ColorMap -> cm_vpe;
  2261.  
  2262.             ScreenWidth    = Extra -> DisplayClip . MaxX - Extra -> DisplayClip . MinX + 1;
  2263.             ScreenHeight    = Extra -> DisplayClip . MaxY - Extra -> DisplayClip . MinY + 1;
  2264.         }
  2265.         else
  2266.         {
  2267.             struct ViewPortExtra *Extra;
  2268.  
  2269.             if(Extra = (struct ViewPortExtra *)GfxLookUp(VPort))
  2270.             {
  2271.                 ScreenWidth    = Extra -> DisplayClip . MaxX - Extra -> DisplayClip . MinX + 1;
  2272.                 ScreenHeight    = Extra -> DisplayClip . MaxY - Extra -> DisplayClip . MinY + 1;
  2273.             }
  2274.             else
  2275.             {
  2276.                 ScreenWidth    = LocalScreen -> Width;
  2277.                 ScreenHeight    = LocalScreen -> Height;
  2278.             }
  2279.         }
  2280.  
  2281.         DepthMask = (1L << GetBitMapDepth(LocalScreen -> RastPort . BitMap)) - 1;
  2282.  
  2283.         switch(Config -> ScreenConfig -> ColourMode)
  2284.         {
  2285.             case COLOUR_SIXTEEN:
  2286.  
  2287.                 if(DepthMask < 15)
  2288.                 {
  2289.                     if(DepthMask >= 7)
  2290.                         Config -> ScreenConfig -> ColourMode = COLOUR_EIGHT;
  2291.                     else
  2292.                     {
  2293.                         if(DepthMask >= 3)
  2294.                             Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2295.                         else
  2296.                             Config -> ScreenConfig -> ColourMode = COLOUR_MONO;
  2297.                     }
  2298.                 }
  2299.  
  2300.                 break;
  2301.  
  2302.             case COLOUR_EIGHT:
  2303.  
  2304.                 if(DepthMask < 7)
  2305.                 {
  2306.                     if(DepthMask >= 3)
  2307.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2308.                     else
  2309.                         Config -> ScreenConfig -> ColourMode = COLOUR_MONO;
  2310.                 }
  2311.  
  2312.                 break;
  2313.  
  2314.             case COLOUR_AMIGA:
  2315.  
  2316.                 if(DepthMask < 3)
  2317.                     Config -> ScreenConfig -> ColourMode = COLOUR_MONO;
  2318.  
  2319.                 break;
  2320.         }
  2321.  
  2322.         if(!(DrawInfo = GetScreenDrawInfo(LocalScreen)))
  2323.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_SCREEN_DRAWINFO_TXT));
  2324.  
  2325.         CreateMenuGlyphs(LocalScreen,DrawInfo,&AmigaGlyph,&CheckGlyph);
  2326.  
  2327.         SZ_SizeSetup(LocalScreen,&UserFont);
  2328.  
  2329.             /* Obtain visual info (whatever that may be). */
  2330.  
  2331.         if(!(VisualInfo = GetVisualInfo(LocalScreen,TAG_DONE)))
  2332.         {
  2333.                 /* Delete the DrawInfo now, or it won't
  2334.                  * get freed during shutdown.
  2335.                  */
  2336.  
  2337.             FreeScreenDrawInfo(LocalScreen,DrawInfo);
  2338.  
  2339.             DrawInfo = NULL;
  2340.  
  2341.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_VISUAL_INFO_TXT));
  2342.         }
  2343.  
  2344.         if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED && !Config -> ScreenConfig -> SplitStatus)
  2345.             FullWidth = StatusWidth;
  2346.         else
  2347.             FullWidth = 0;
  2348.  
  2349.         if(WindowBox . Left != -1)
  2350.         {
  2351.             SomeTags[Index  ] . ti_Tag    = WA_Left;
  2352.             SomeTags[Index++] . ti_Data    = WindowBox . Left;
  2353.             SomeTags[Index  ] . ti_Tag    = WA_Top;
  2354.             SomeTags[Index++] . ti_Data    = WindowBox . Top;
  2355.  
  2356.             SomeTags[Index  ] . ti_Tag    = WA_Width;
  2357.             SomeTags[Index++] . ti_Data    = WindowBox . Width;
  2358.             SomeTags[Index  ] . ti_Tag    = WA_Height;
  2359.             SomeTags[Index++] . ti_Data    = WindowBox . Height;
  2360.  
  2361.             WindowBox . Left = -1;
  2362.         }
  2363.         else
  2364.         {
  2365.             LONG WindowLeft = -1,WindowTop = -1,DummyWidth,DummyHeight;
  2366.  
  2367.             GetWindowInfo(WINDOW_MAIN,&WindowLeft,&WindowTop,&DummyWidth,&DummyHeight,0,0);
  2368.  
  2369.             if(Config -> TerminalConfig -> NumColumns < 20)
  2370.             {
  2371.                 LONG Width = GetScreenWidth(NULL);
  2372.  
  2373.                 if(FullWidth && Width < FullWidth)
  2374.                 {
  2375.                     SomeTags[Index  ] . ti_Tag    = WA_InnerWidth;
  2376.                     SomeTags[Index++] . ti_Data    = FullWidth;
  2377.                 }
  2378.                 else
  2379.                 {
  2380.                     SomeTags[Index  ] . ti_Tag    = WA_Width;
  2381.                     SomeTags[Index++] . ti_Data    = Width;
  2382.                 }
  2383.             }
  2384.             else
  2385.             {
  2386.                 SomeTags[Index  ] . ti_Tag    = WA_InnerWidth;
  2387.                 SomeTags[Index++] . ti_Data    = Config -> TerminalConfig -> NumColumns * TextFontWidth;
  2388.             }
  2389.  
  2390.             if(Config -> TerminalConfig -> NumLines < 20)
  2391.             {
  2392.                 SomeTags[Index  ] . ti_Tag    = WA_Height;
  2393.                 SomeTags[Index++] . ti_Data    = GetScreenHeight(NULL) - (LocalScreen -> BarHeight + 1);
  2394.             }
  2395.             else
  2396.             {
  2397.                 SomeTags[Index  ] . ti_Tag    = WA_InnerHeight;
  2398.                 SomeTags[Index++] . ti_Data    = Config -> TerminalConfig -> NumLines * TextFontHeight + StatusHeight;
  2399.             }
  2400.  
  2401.             if(WindowLeft != -1)
  2402.             {
  2403.                 SomeTags[Index  ] . ti_Tag    = WA_Left;
  2404.                 SomeTags[Index++] . ti_Data    = WindowLeft;
  2405.             }
  2406.             else
  2407.             {
  2408.                 SomeTags[Index  ] . ti_Tag    = WA_Left;
  2409.                 SomeTags[Index++] . ti_Data    = GetScreenLeft(NULL);
  2410.             }
  2411.  
  2412.             if(WindowTop != -1)
  2413.             {
  2414.                 SomeTags[Index  ] . ti_Tag    = WA_Top;
  2415.                 SomeTags[Index++] . ti_Data    = WindowTop;
  2416.             }
  2417.         }
  2418.  
  2419.         SomeTags[Index] . ti_Tag = TAG_DONE;
  2420.  
  2421.             /* Open the main window. */
  2422.  
  2423.         if(!(Window = OpenWindowTags(NULL,
  2424.             WA_MaxHeight,        LocalScreen -> Height,
  2425.             WA_MaxWidth,        LocalScreen -> Width,
  2426.             WA_SmartRefresh,    TRUE,
  2427.             WA_CustomScreen,    LocalScreen,
  2428.             WA_NewLookMenus,    TRUE,
  2429.             WA_RMBTrap,        TRUE,
  2430.             WA_IDCMP,        IDCMP_RAWKEY | IDCMP_INACTIVEWINDOW | IDCMP_ACTIVEWINDOW | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_MENUPICK | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE | IDCMP_IDCMPUPDATE | IDCMP_MENUHELP,
  2431.             WA_DragBar,        TRUE,
  2432.             WA_DepthGadget,        TRUE,
  2433.             WA_CloseGadget,        TRUE,
  2434.             WA_SizeGadget,        TRUE,
  2435.             WA_SizeBBottom,        Config -> ScreenConfig -> StatusLine == STATUSLINE_DISABLED || Config -> ScreenConfig -> SplitStatus,
  2436.             WA_NoCareRefresh,    TRUE,
  2437.             WA_Title,        ScreenTitle,
  2438.             WA_MenuHelp,        TRUE,
  2439.  
  2440.             AmigaGlyph ? WA_AmigaKey  : TAG_IGNORE, AmigaGlyph,
  2441.             CheckGlyph ? WA_Checkmark : TAG_IGNORE, CheckGlyph,
  2442.  
  2443.             TAG_MORE,        SomeTags,
  2444.         TAG_DONE)))
  2445.         {
  2446.                 /* Delete the DrawInfo now, or it won't
  2447.                  * get freed during shutdown.
  2448.                  */
  2449.  
  2450.             FreeScreenDrawInfo(LocalScreen,DrawInfo);
  2451.  
  2452.             DrawInfo = NULL;
  2453.  
  2454.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  2455.         }
  2456.  
  2457.         if(StatusHeight)
  2458.         {
  2459.             StatusDisplayHeight = StatusHeight;
  2460.  
  2461.             CopyMem(Window -> RPort,StatusRPort = &StatusRastPort,sizeof(struct RastPort));
  2462.  
  2463.             StatusRPort -> BitMap = Window -> RPort -> BitMap;
  2464.         }
  2465.         else
  2466.             StatusRPort = NULL;
  2467.  
  2468.             /* Create a user clip region to keep text from
  2469.              * leaking into the window borders.
  2470.              */
  2471.  
  2472.         if(!(ClipRegion = NewRegion()))
  2473.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  2474.         else
  2475.         {
  2476.             struct Rectangle RegionRectangle;
  2477.  
  2478.                 /* Adjust the region to match the inner window area. */
  2479.  
  2480.             RegionRectangle . MinX = Window -> BorderLeft;
  2481.             RegionRectangle . MinY = Window -> BorderTop;
  2482.             RegionRectangle . MaxX = Window -> Width - (Window -> BorderRight + 1);
  2483.             RegionRectangle . MaxY = Window -> Height - (Window -> BorderBottom + 1);
  2484.  
  2485.                 /* Establish the region. */
  2486.  
  2487.             OrRectRegion(ClipRegion,&RegionRectangle);
  2488.  
  2489.                 /* Install the region. */
  2490.  
  2491.             OldRegion = InstallClipRegion(Window -> WLayer,ClipRegion);
  2492.         }
  2493.  
  2494.         if(FullWidth < 40 * TextFontWidth)
  2495.             FullWidth = 40 * TextFontWidth;
  2496.  
  2497.         Width    = Window -> BorderLeft + FullWidth + Window -> BorderRight;
  2498.         Height    = Window -> BorderTop + 20 * TextFontHeight + Window -> BorderBottom + StatusHeight;
  2499.  
  2500.         if(ChatMode && !(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0]))
  2501.             Height += UserFontHeight + 2;
  2502.  
  2503.         WindowLimits(Window,Width,Height,0,0);
  2504.  
  2505.         if(WorkbenchBase)
  2506.         {
  2507.             if(WorkbenchPort = CreateMsgPort())
  2508.             {
  2509.                 if(!(WorkbenchWindow = AddAppWindow(0,0,Window,WorkbenchPort,TAG_DONE)))
  2510.                 {
  2511.                     DeleteMsgPort(WorkbenchPort);
  2512.  
  2513.                     WorkbenchPort = NULL;
  2514.                 }
  2515.             }
  2516.         }
  2517.     }
  2518.     else
  2519.     {
  2520.         struct DimensionInfo    DimensionInfo;
  2521.         WORD            MaxDepth,
  2522.                     ScreenDepth;
  2523.  
  2524.         if(ModeNotAvailable(Config -> ScreenConfig -> DisplayMode))
  2525.         {
  2526.             struct Screen *PubScreen;
  2527.  
  2528.             if(PubScreen = LockPubScreen(NULL))
  2529.             {
  2530.                 Config -> ScreenConfig -> DisplayMode = GetVPModeID(&PubScreen -> ViewPort);
  2531.  
  2532.                 if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2533.                 {
  2534.                     LONG    Width    = DimensionInfo . TxtOScan . MaxX - DimensionInfo . TxtOScan . MinX + 1,
  2535.                         Height    = DimensionInfo . TxtOScan . MaxY - DimensionInfo . TxtOScan . MinY + 1;
  2536.  
  2537.                     if(Width != Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayWidth)
  2538.                         Config -> ScreenConfig -> DisplayWidth = Width;
  2539.  
  2540.                     if(Height != Config -> ScreenConfig -> DisplayHeight && Config -> ScreenConfig -> DisplayHeight)
  2541.                         Config -> ScreenConfig -> DisplayHeight = Height;
  2542.                 }
  2543.  
  2544.                 UnlockPubScreen(NULL,PubScreen);
  2545.             }
  2546.         }
  2547.  
  2548.         if(!QueryOverscan(Config -> ScreenConfig -> DisplayMode,&DisplayClip,Config -> ScreenConfig -> OverscanType))
  2549.         {
  2550.             OpenFailed = TRUE;
  2551.  
  2552.             ErrorCode = ModeNotAvailable(Config -> ScreenConfig -> DisplayMode);
  2553.  
  2554.             goto OpenS;
  2555.         }
  2556.  
  2557.         if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2558.         {
  2559.             UWORD    MaxWidth,
  2560.                 MaxHeight,
  2561.                 Width,
  2562.                 Height;
  2563.  
  2564.             MaxWidth    = DisplayClip . MaxX - DisplayClip . MinX + 1;
  2565.             MaxHeight    = DisplayClip . MaxY - DisplayClip . MinY + 1;
  2566.  
  2567.             if(Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayHeight && AslBase -> lib_Version >= 38)
  2568.             {
  2569.                 ScreenWidth    = Config -> ScreenConfig -> DisplayWidth;
  2570.                 ScreenHeight    = Config -> ScreenConfig -> DisplayHeight;
  2571.             }
  2572.             else
  2573.             {
  2574.                 ScreenWidth    = MaxWidth;
  2575.                 ScreenHeight    = MaxHeight;
  2576.             }
  2577.  
  2578.             if(Config -> TerminalConfig -> NumColumns < 20)
  2579.                 Width = MaxWidth = ScreenWidth;
  2580.             else
  2581.             {
  2582.                 Width = TextFontWidth * Config -> TerminalConfig -> NumColumns;
  2583.  
  2584.                 ScreenWidth = 0;
  2585.             }
  2586.  
  2587.             if(Config -> TerminalConfig -> NumLines < 20)
  2588.                 Height = MaxHeight = ScreenHeight;
  2589.             else
  2590.             {
  2591.                 Height = TextFontHeight * Config -> TerminalConfig -> NumLines;
  2592.  
  2593.                 if(Config -> ScreenConfig -> TitleBar)
  2594.                     Height += UserFontHeight + 3;
  2595.  
  2596.                 if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED)
  2597.                 {
  2598.                     if(Config -> ScreenConfig -> StatusLine == STATUSLINE_COMPRESSED)
  2599.                         Height += UserFontHeight;
  2600.                     else
  2601.                         Height += 4 + (2 + 2 * UserFontHeight + 2);
  2602.                 }
  2603.  
  2604.                 ScreenHeight = 0;
  2605.             }
  2606.  
  2607.             if(Height > MaxHeight)
  2608.                 Height = MaxHeight;
  2609.  
  2610.             if(Width > MaxWidth)
  2611.                 Width = MaxWidth;
  2612.  
  2613.             if(DimensionInfo . MinRasterWidth <= Width && Width <= DimensionInfo . MaxRasterWidth)
  2614.             {
  2615.                 UWORD Half;
  2616.  
  2617.                 Width = MaxWidth - Width;
  2618.  
  2619.                 Half = Width / 2;
  2620.  
  2621.                 DisplayClip . MinX += Half;
  2622.                 DisplayClip . MaxX -= Width - Half;
  2623.             }
  2624.  
  2625.             if(DimensionInfo . MinRasterHeight <= Height && Height <= DimensionInfo . MaxRasterHeight)
  2626.                 DisplayClip . MaxY = DisplayClip . MinY + Height - 1;
  2627.  
  2628.             if(!ScreenWidth)
  2629.                 ScreenWidth = DisplayClip . MaxX - DisplayClip . MinX + 1;
  2630.  
  2631.             if(!ScreenHeight)
  2632.                 ScreenHeight = DisplayClip . MaxY - DisplayClip . MinY + 1;
  2633.  
  2634.             MaxDepth = DimensionInfo . MaxDepth;
  2635.         }
  2636.         else
  2637.         {
  2638.             ScreenWidth = ScreenHeight = 0;
  2639.             MaxDepth = 4;
  2640.         }
  2641.  
  2642.             /* We'll configure the screen parameters at
  2643.              * run time, at first we'll set up the screen
  2644.              * depth.
  2645.              */
  2646.  
  2647. PenReset:    if(!Config -> ScreenConfig -> UsePens && Kick30)
  2648.         {
  2649.             for(i = DETAILPEN ; i <= BARTRIMPEN ; i++)
  2650.                 PenArray[i] = Config -> ScreenConfig -> PenArray[i];
  2651.  
  2652.             PenArray[i] = (UWORD)~0;
  2653.         }
  2654.         else
  2655.         {
  2656.             UWORD *Data;
  2657.  
  2658.             switch(Config -> ScreenConfig -> ColourMode)
  2659.             {
  2660.                 case COLOUR_EIGHT:
  2661.  
  2662.                     Data = ANSIPens;
  2663.                     break;
  2664.  
  2665.                 case COLOUR_SIXTEEN:
  2666.  
  2667.                     if(IntuitionBase -> LibNode . lib_Version >= 39)
  2668.                         Data = NewEGAPens;
  2669.                     else
  2670.                         Data = EGAPens;
  2671.  
  2672.                     break;
  2673.  
  2674.                 case COLOUR_AMIGA:
  2675.  
  2676.                     Data = StandardPens;
  2677.                     break;
  2678.  
  2679.                 default:
  2680.  
  2681.                     Data = NULL;
  2682.                     break;
  2683.             }
  2684.  
  2685.             if(Data)
  2686.             {
  2687.                 for(i = DETAILPEN ; i <= BARTRIMPEN ; i++)
  2688.                     PenArray[i] = Data[i];
  2689.  
  2690.                 PenArray[i] = (UWORD)~0;
  2691.             }
  2692.         }
  2693.  
  2694.         switch(Config -> ScreenConfig -> ColourMode)
  2695.         {
  2696.             case COLOUR_EIGHT:
  2697.  
  2698.                     // Special screen depth requested?
  2699.  
  2700.                 if(Config -> ScreenConfig -> Depth)
  2701.                 {
  2702.                         // The minimum number of colours required
  2703.  
  2704.                     if(Config -> ScreenConfig -> Blinking)
  2705.                         ScreenDepth = 4;
  2706.                     else
  2707.                         ScreenDepth = 3;
  2708.  
  2709.                         // This is what the user wanted
  2710.  
  2711.                     RealDepth = Config -> ScreenConfig -> Depth;
  2712.  
  2713.                         // Too deep for this display mode?
  2714.  
  2715.                     if(RealDepth > MaxDepth)
  2716.                         RealDepth = MaxDepth;
  2717.  
  2718.                         // Less colours than required?
  2719.  
  2720.                     if(RealDepth < ScreenDepth && ScreenDepth <= MaxDepth)
  2721.                         RealDepth = ScreenDepth;
  2722.  
  2723.                         // Not enough colours to display it?
  2724.  
  2725.                     if(RealDepth < ScreenDepth)
  2726.                     {
  2727.                             // Return to standard mode
  2728.  
  2729.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2730.  
  2731.                         ConfigChanged = TRUE;
  2732.  
  2733.                         goto PenReset;
  2734.                     }
  2735.                 }
  2736.                 else
  2737.                 {
  2738.                         // The minimum number of colours
  2739.  
  2740.                     if(Config -> ScreenConfig -> Blinking)
  2741.                         ScreenDepth = 4;
  2742.                     else
  2743.                         ScreenDepth = 3;
  2744.  
  2745.                         // Too many for this mode?
  2746.  
  2747.                     if(ScreenDepth > MaxDepth)
  2748.                     {
  2749.                             // Return to standard mode
  2750.  
  2751.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2752.  
  2753.                         ConfigChanged = TRUE;
  2754.  
  2755.                         goto PenReset;
  2756.                     }
  2757.  
  2758.                     RealDepth = ScreenDepth;
  2759.                 }
  2760.  
  2761.                 TagArray[Count++] = SA_Pens;
  2762.                 TagArray[Count++] = (LONG)PenArray;
  2763.  
  2764.                 TagArray[Count++] = SA_BlockPen;
  2765.                 TagArray[Count++] = PenArray[SHADOWPEN];
  2766.  
  2767.                 TagArray[Count++] = SA_DetailPen;
  2768.                 TagArray[Count++] = PenArray[BACKGROUNDPEN];
  2769.  
  2770.                 break;
  2771.  
  2772.             case COLOUR_SIXTEEN:
  2773.  
  2774.                 if(Config -> ScreenConfig -> Depth)
  2775.                 {
  2776.                     if(Config -> ScreenConfig -> Blinking && MaxDepth > 4)
  2777.                         ScreenDepth = 5;
  2778.                     else
  2779.                         ScreenDepth = 4;
  2780.  
  2781.                     RealDepth = Config -> ScreenConfig -> Depth;
  2782.  
  2783.                     if(RealDepth > MaxDepth)
  2784.                         RealDepth = MaxDepth;
  2785.  
  2786.                     if(RealDepth < ScreenDepth && ScreenDepth <= MaxDepth)
  2787.                         RealDepth = ScreenDepth;
  2788.  
  2789.                     if(RealDepth < ScreenDepth)
  2790.                     {
  2791.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2792.  
  2793.                         ConfigChanged = TRUE;
  2794.  
  2795.                         goto PenReset;
  2796.                     }
  2797.                 }
  2798.                 else
  2799.                 {
  2800.                     if(Config -> ScreenConfig -> Blinking && MaxDepth > 4)
  2801.                         ScreenDepth = 5;
  2802.                     else
  2803.                         ScreenDepth = 4;
  2804.  
  2805.                     if(ScreenDepth > MaxDepth)
  2806.                     {
  2807.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2808.  
  2809.                         ConfigChanged = TRUE;
  2810.  
  2811.                         goto PenReset;
  2812.                     }
  2813.  
  2814.                     RealDepth = ScreenDepth;
  2815.                 }
  2816.  
  2817.                 TagArray[Count++] = SA_Pens;
  2818.                 TagArray[Count++] = (LONG)PenArray;
  2819.  
  2820.                 TagArray[Count++] = SA_BlockPen;
  2821.                 TagArray[Count++] = PenArray[SHADOWPEN];
  2822.  
  2823.                 TagArray[Count++] = SA_DetailPen;
  2824.                 TagArray[Count++] = PenArray[BACKGROUNDPEN];
  2825.  
  2826.                 break;
  2827.  
  2828.             case COLOUR_MONO:
  2829.  
  2830.                 if(Config -> ScreenConfig -> Depth)
  2831.                     RealDepth = Config -> ScreenConfig -> Depth;
  2832.                 else
  2833.                     RealDepth = 1;
  2834.  
  2835.                 if(RealDepth > MaxDepth)
  2836.                     RealDepth = MaxDepth;
  2837.  
  2838.                 break;
  2839.  
  2840.             case COLOUR_AMIGA:
  2841.  
  2842.                 if(Config -> ScreenConfig -> Depth)
  2843.                     RealDepth = Config -> ScreenConfig -> Depth;
  2844.                 else
  2845.                     RealDepth = 2;
  2846.  
  2847.                 if(RealDepth > MaxDepth)
  2848.                     RealDepth = MaxDepth;
  2849.  
  2850.                 TagArray[Count++] = SA_Pens;
  2851.                 TagArray[Count++] = (LONG)PenArray;
  2852.  
  2853.                 break;
  2854.         }
  2855.  
  2856.             /* Add the depth value. */
  2857.  
  2858.         TagArray[Count++] = SA_Depth;
  2859.         TagArray[Count++] = RealDepth;
  2860.  
  2861.             /* Terminate the tag array. */
  2862.  
  2863.         TagArray[Count] = TAG_END;
  2864.  
  2865.             /* Set the plane mask. */
  2866.  
  2867.         DepthMask = (1L << RealDepth) - 1;
  2868.  
  2869. #ifdef _M68030
  2870. OpenS:        SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"'030 ",TermDate,TermIDString);
  2871. #else
  2872. OpenS:        SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"",TermDate,TermIDString);
  2873. #endif    /* _M68030 */
  2874.  
  2875.         /* ALWAYS */
  2876.         {
  2877.             BYTE Interleaved;
  2878.  
  2879.             if(Config -> ScreenConfig -> FasterLayout && Kick30 && RealDepth > 1)
  2880.                 Interleaved = TRUE;
  2881.             else
  2882.                 Interleaved = FALSE;
  2883.  
  2884.             if(Screen = (struct Screen *)OpenScreenTags(NULL,
  2885.                 ScreenWidth  ? SA_Width  : TAG_IGNORE,    ScreenWidth,
  2886.                 ScreenHeight ? SA_Height : TAG_IGNORE,    ScreenHeight,
  2887.  
  2888.                 SA_Title,    ScreenTitle,
  2889.                 SA_DClip,    &DisplayClip,
  2890.                 SA_DisplayID,    Config -> ScreenConfig -> DisplayMode,
  2891.                 SA_Font,    &UserFont,
  2892.                 SA_Behind,    TRUE,
  2893.                 SA_AutoScroll,    TRUE,
  2894.                 SA_ShowTitle,    Config -> ScreenConfig -> TitleBar,
  2895.                 SA_PubName,    TermIDString,
  2896.                 SA_ErrorCode,    &ErrorCode,
  2897.                 SA_Interleaved,    Interleaved,
  2898.                 SA_BackFill,    &BackfillHook,
  2899.                 TAG_MORE,    TagArray,
  2900.             TAG_END))
  2901.             {
  2902.                 UseMasking = TRUE;
  2903.  
  2904.                 if(Kick30)
  2905.                 {
  2906.                     if(GetBitMapAttr(Screen -> RastPort . BitMap,BMA_FLAGS) & BMF_INTERLEAVED)
  2907.                         UseMasking = FALSE;
  2908.                 }
  2909.             }
  2910.         }
  2911.  
  2912.             /* We've got an error. */
  2913.  
  2914.         if(!Screen)
  2915.         {
  2916.             if(!OpenFailed)
  2917.             {
  2918.                 struct Screen *PubScreen;
  2919.  
  2920.                 switch(ErrorCode)
  2921.                 {
  2922.                         /* Can't open screen with these display
  2923.                          * modes.
  2924.                          */
  2925.  
  2926.                     case OSERR_NOMONITOR:
  2927.                     case OSERR_NOCHIPS:
  2928.                     case OSERR_UNKNOWNMODE:
  2929.                     case OSERR_NOTAVAILABLE:
  2930.  
  2931.                         if(PubScreen = LockPubScreen(NULL))
  2932.                         {
  2933.                             struct DimensionInfo DimensionInfo;
  2934.  
  2935.                             Config -> ScreenConfig -> DisplayMode = GetVPModeID(&PubScreen -> ViewPort);
  2936.  
  2937.                             if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2938.                             {
  2939.                                 LONG    Width    = DimensionInfo . TxtOScan . MaxX - DimensionInfo . TxtOScan . MinX + 1,
  2940.                                     Height    = DimensionInfo . TxtOScan . MaxY - DimensionInfo . TxtOScan . MinY + 1;
  2941.  
  2942.                                 if(Width != Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayWidth)
  2943.                                     Config -> ScreenConfig -> DisplayWidth = Width;
  2944.  
  2945.                                 if(Height != Config -> ScreenConfig -> DisplayHeight && Config -> ScreenConfig -> DisplayHeight)
  2946.                                     Config -> ScreenConfig -> DisplayHeight = Height;
  2947.                             }
  2948.  
  2949.                             UnlockPubScreen(NULL,PubScreen);
  2950.                         }
  2951.                         else
  2952.                             Config -> ScreenConfig -> DisplayMode = DEFAULT_MONITOR_ID | HIRESLACE_KEY;
  2953.  
  2954.                         OpenFailed = TRUE;
  2955.  
  2956.                         goto OpenS;
  2957.  
  2958.                     case OSERR_PUBNOTUNIQUE:
  2959.  
  2960.                         return(LocaleString(MSG_TERMINIT_SCREEN_ID_ALREADY_IN_USE_TXT));
  2961.                 }
  2962.             }
  2963.  
  2964.                 /* Some different error, probably out of
  2965.                  * memory.
  2966.                  */
  2967.  
  2968.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_SCREEN_TXT));
  2969.         }
  2970.  
  2971.         if(!(DrawInfo = GetScreenDrawInfo(Screen)))
  2972.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_SCREEN_DRAWINFO_TXT));
  2973.  
  2974.         CreateMenuGlyphs(Screen,DrawInfo,&AmigaGlyph,&CheckGlyph);
  2975.  
  2976.         VPort = &Screen -> ViewPort;
  2977.  
  2978.         ScreenWidth    = Screen -> Width;
  2979.         ScreenHeight    = Screen -> Height;
  2980.  
  2981.         StatusSizeSetup(Screen,&StatusWidth,&StatusHeight);
  2982.  
  2983.             /* Obtain visual info (whatever that may be). */
  2984.  
  2985.         if(!(VisualInfo = GetVisualInfo(Screen,TAG_DONE)))
  2986.         {
  2987.                 /* Delete the DrawInfo now, or it won't
  2988.                  * get freed during shutdown.
  2989.                  */
  2990.  
  2991.             FreeScreenDrawInfo(Screen,DrawInfo);
  2992.  
  2993.             DrawInfo = NULL;
  2994.  
  2995.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_VISUAL_INFO_TXT));
  2996.         }
  2997.  
  2998.         if(Config -> ScreenConfig -> TitleBar)
  2999.         {
  3000.             Top = Screen -> BarHeight + 1;
  3001.  
  3002.             Height = Screen -> Height - (Screen -> BarHeight + 1);
  3003.         }
  3004.         else
  3005.         {
  3006.             Top = 0;
  3007.  
  3008.             Height = Screen -> Height;
  3009.         }
  3010.  
  3011.             /* Open the main window. */
  3012.  
  3013.         if(!(Window = OpenWindowTags(NULL,
  3014.             WA_Top,        Top,
  3015.             WA_Left,    0,
  3016.             WA_Width,    Screen -> Width,
  3017.             WA_Height,    Height,
  3018.             WA_Backdrop,    TRUE,
  3019.             WA_Borderless,    TRUE,
  3020.             WA_SmartRefresh,TRUE,
  3021.             WA_CustomScreen,Screen,
  3022.             WA_NewLookMenus,TRUE,
  3023.             WA_RMBTrap,    TRUE,
  3024.             WA_IDCMP,    IDCMP_RAWKEY | IDCMP_INACTIVEWINDOW | IDCMP_ACTIVEWINDOW | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_MENUPICK | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE | IDCMP_SIZEVERIFY | IDCMP_IDCMPUPDATE | IDCMP_MENUHELP,
  3025.             WA_MenuHelp,    TRUE,
  3026.  
  3027.             AmigaGlyph ? WA_AmigaKey  : TAG_IGNORE, AmigaGlyph,
  3028.             CheckGlyph ? WA_Checkmark : TAG_IGNORE, CheckGlyph,
  3029.         TAG_DONE)))
  3030.         {
  3031.                 /* Delete the DrawInfo now, or it won't
  3032.                  * get freed during shutdown.
  3033.                  */
  3034.  
  3035.             FreeScreenDrawInfo(Screen,DrawInfo);
  3036.  
  3037.             DrawInfo = NULL;
  3038.  
  3039.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  3040.         }
  3041.  
  3042.         if(StatusHeight)
  3043.         {
  3044.             StatusDisplayHeight = StatusHeight;
  3045.  
  3046.             CopyMem(Window -> RPort,StatusRPort = &StatusRastPort,sizeof(struct RastPort));
  3047.  
  3048.             StatusRPort -> BitMap = Window -> RPort -> BitMap;
  3049.         }
  3050.         else
  3051.             StatusRPort = NULL;
  3052.     }
  3053.  
  3054.         /* Fill the `default' colour with current values. */
  3055.  
  3056.     if(!Config -> ScreenConfig -> UseWorkbench && Initializing && !SharedScreen)
  3057.     {
  3058.         if(Kick30)
  3059.         {
  3060.             ANSIColourTable = CreateColourTable(8,ANSIColours,NULL);
  3061.             EGAColourTable = CreateColourTable(16,EGAColours,NULL);
  3062.  
  3063.             if(DefaultColourTable = CreateColourTable(16,NULL,NULL))
  3064.                 GetRGB32(VPort -> ColorMap,0,16,(ULONG *)&DefaultColourTable -> Entry[0]);
  3065.  
  3066.             MonoColourTable = CreateColourTable(2,AtomicColours,NULL);
  3067.         }
  3068.  
  3069.         for(i = 0 ; i < 16 ; i++)
  3070.             DefaultColours[i] = GetRGB4(VPort -> ColorMap,i);
  3071.  
  3072.         Initializing = FALSE;
  3073.     }
  3074.  
  3075.         /* Load the approriate colours. */
  3076.  
  3077.     if(LoadColours)
  3078.     {
  3079.         Default2CurrentPalette(Config);
  3080.  
  3081.         LoadColours = FALSE;
  3082.     }
  3083.  
  3084.         /* Reset the current colours and the blinking equivalents. */
  3085.  
  3086.     PaletteSetup(Config);
  3087.  
  3088.     if(!Config -> ScreenConfig -> UseWorkbench && !SharedScreen)
  3089.         LoadColourTable(VPort,NormalColourTable,NormalColours,PaletteSize);
  3090.  
  3091.         /* Get the vanilla rendering pens. */
  3092.  
  3093.     RenderPens[0] = DrawInfo -> dri_Pens[BACKGROUNDPEN];
  3094.     RenderPens[1] = DrawInfo -> dri_Pens[TEXTPEN];
  3095.     RenderPens[2] = DrawInfo -> dri_Pens[SHINEPEN];
  3096.     RenderPens[3] = DrawInfo -> dri_Pens[FILLPEN];
  3097.  
  3098.         /* Are we to use the Workbench screen for text output? */
  3099.  
  3100.     if(Config -> ScreenConfig -> UseWorkbench || (SharedScreen && Kick30))
  3101.     {
  3102.         if(Kick30 && (Config -> ScreenConfig -> ColourMode == COLOUR_EIGHT || Config -> ScreenConfig -> ColourMode == COLOUR_SIXTEEN))
  3103.         {
  3104.             ULONG    R,G,B;
  3105.             BYTE    GotAll = TRUE;
  3106.             WORD    NumPens;
  3107.  
  3108.             if(Config -> ScreenConfig -> ColourMode == COLOUR_EIGHT)
  3109.                 NumPens = 8;
  3110.             else
  3111.                 NumPens = 16;
  3112.  
  3113.             for(i = 0 ; i < 16 ; i++)
  3114.                 MappedPens[1][i] = FALSE;
  3115.  
  3116.                 /* Allocate the text rendering pens, note that
  3117.                  * we will use the currently installed palette
  3118.                  * to obtain those pens which match them best.
  3119.                  * The user will be unable to change these
  3120.                  * colours.
  3121.                  */
  3122.  
  3123.             if(NormalColourTable)
  3124.             {
  3125.                 for(i = 0 ; i < NumPens ; i++)
  3126.                 {
  3127.                         /* Try to obtain a matching pen. */
  3128.  
  3129.                     if((MappedPens[0][i] = ObtainBestPen(VPort -> ColorMap,NormalColourTable -> Entry[i] . Red,NormalColourTable -> Entry[i] . Green,NormalColourTable -> Entry[i] . Blue,
  3130.                         OBP_FailIfBad,TRUE,
  3131.                     TAG_DONE)) == -1)
  3132.                     {
  3133.                         MappedPens[1][i] = FALSE;
  3134.  
  3135.                         GotAll = FALSE;
  3136.  
  3137.                         break;
  3138.                     }
  3139.                     else
  3140.                         MappedPens[1][i] = TRUE;
  3141.                 }
  3142.             }
  3143.             else
  3144.             {
  3145.                 for(i = 0 ; i < NumPens ; i++)
  3146.                 {
  3147.                         /* Split the 12 bit colour palette entry. */
  3148.  
  3149.                     R = (NormalColours[i] >> 8) & 0xF;
  3150.                     G = (NormalColours[i] >> 4) & 0xF;
  3151.                     B =  NormalColours[i]       & 0xF;
  3152.  
  3153.                         /* Try to obtain a matching pen. */
  3154.  
  3155.                     if((MappedPens[0][i] = ObtainBestPen(VPort -> ColorMap,SPREAD((R << 4) | R),SPREAD((G << 4) | G),SPREAD((B << 4) | B),
  3156.                         OBP_FailIfBad,TRUE,
  3157.                     TAG_DONE)) == -1)
  3158.                     {
  3159.                         MappedPens[1][i] = FALSE;
  3160.  
  3161.                         GotAll = FALSE;
  3162.  
  3163.                         break;
  3164.                     }
  3165.                     else
  3166.                         MappedPens[1][i] = TRUE;
  3167.                 }
  3168.             }
  3169.  
  3170.                 /* Did we get what we wanted? */
  3171.  
  3172.             if(!GotAll)
  3173.             {
  3174.                     /* Release all the pens we succeeded
  3175.                      * in allocating.
  3176.                      */
  3177.  
  3178.                 for(i = 0 ; i < NumPens ; i++)
  3179.                 {
  3180.                     if(MappedPens[1][i])
  3181.                         ReleasePen(VPort -> ColorMap,MappedPens[0][i]);
  3182.                 }
  3183.  
  3184.                     /* Use the default rendering pens. */
  3185.  
  3186.                 for(i = 0 ; i < 4 ; i++)
  3187.                 {
  3188.                     MappedPens[0][i] = RenderPens[i];
  3189.                     MappedPens[1][i] = FALSE;
  3190.                 }
  3191.  
  3192.                     /* Set the remaining pens to defaults. */
  3193.  
  3194.                 for(i = 4 ; i < NumPens ; i++)
  3195.                 {
  3196.                     MappedPens[0][i] = RenderPens[1];
  3197.                     MappedPens[1][i] = FALSE;
  3198.                 }
  3199.  
  3200.                     /* Can't do anything else. */
  3201.  
  3202.                 Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  3203.             }
  3204.             else
  3205.                 AllocatedPens = TRUE;
  3206.         }
  3207.         else
  3208.         {
  3209.                 /* Use the default rendering pens. */
  3210.  
  3211.             if(Config -> ScreenConfig -> ColourMode == COLOUR_AMIGA)
  3212.             {
  3213.                 for(i = 0 ; i < 4 ; i++)
  3214.                 {
  3215.                     MappedPens[0][i] = RenderPens[i];
  3216.                     MappedPens[1][i] = FALSE;
  3217.                 }
  3218.  
  3219.                     /* Set the remaining pens to defaults. */
  3220.  
  3221.                 for(i = 4 ; i < 16 ; i++)
  3222.                 {
  3223.                     MappedPens[0][i] = RenderPens[1];
  3224.                     MappedPens[1][i] = FALSE;
  3225.                 }
  3226.             }
  3227.             else
  3228.             {
  3229.                 for(i = 0 ; i < 16 ; i++)
  3230.                 {
  3231.                     MappedPens[0][i] = RenderPens[i & 1];
  3232.                     MappedPens[1][i] = FALSE;
  3233.                 }
  3234.             }
  3235.         }
  3236.  
  3237.         for(i = 0 ; i < 16 ; i++)
  3238.         {
  3239.             MappedPens[0][i + 16] = MappedPens[0][i];
  3240.             MappedPens[1][i + 16] = FALSE;
  3241.         }
  3242.     }
  3243.     else
  3244.     {
  3245.             /* Reset the colour translation table. */
  3246.  
  3247.         for(i = 0 ; i < 32 ; i++)
  3248.         {
  3249.             MappedPens[0][i] = i;
  3250.             MappedPens[1][i] = FALSE;
  3251.         }
  3252.     }
  3253.  
  3254.         /* Determine default text rendering colour. */
  3255.  
  3256.     switch(Config -> ScreenConfig -> ColourMode)
  3257.     {
  3258.         case COLOUR_SIXTEEN:
  3259.  
  3260.             SafeTextPen = MappedPens[0][15];
  3261.             break;
  3262.  
  3263.         case COLOUR_EIGHT:
  3264.  
  3265.             SafeTextPen = MappedPens[0][7];
  3266.             break;
  3267.  
  3268.         case COLOUR_AMIGA:
  3269.         case COLOUR_MONO:
  3270.  
  3271.             SafeTextPen = MappedPens[0][1];
  3272.             break;
  3273.     }
  3274.  
  3275.         /* Take care of pen and attribute mapping. */
  3276.  
  3277.     if(Config -> EmulationConfig -> UseStandardPens)
  3278.     {
  3279.         for(i = 0 ; i < 16 ; i++)
  3280.         {
  3281.             PenTable[i]        = i;
  3282.             TextAttributeTable[i]    = i;
  3283.         }
  3284.     }
  3285.     else
  3286.     {
  3287.         UBYTE Value;
  3288.  
  3289.         memcpy(PenTable,Config -> EmulationConfig -> Pens,sizeof(Config -> EmulationConfig -> Pens));
  3290.  
  3291.         for(i = 0 ; i < 16 ; i++)
  3292.         {
  3293.             Value = 0;
  3294.  
  3295.             if(i & ATTR_UNDERLINE)
  3296.             {
  3297.                 switch(Config -> EmulationConfig -> Attributes[TEXTATTR_UNDERLINE])
  3298.                 {
  3299.                     case TEXTATTR_UNDERLINE:
  3300.  
  3301.                         Value |= ATTR_UNDERLINE;
  3302.                         break;
  3303.  
  3304.                     case TEXTATTR_HIGHLIGHT:
  3305.  
  3306.                         Value |= ATTR_HIGHLIGHT;
  3307.                         break;
  3308.  
  3309.                     case TEXTATTR_BLINK:
  3310.  
  3311.                         Value |= ATTR_BLINK;
  3312.                         break;
  3313.  
  3314.                     case TEXTATTR_INVERSE:
  3315.  
  3316.                         Value |= ATTR_INVERSE;
  3317.                         break;
  3318.                 }
  3319.             }
  3320.  
  3321.             if(i & ATTR_HIGHLIGHT)
  3322.             {
  3323.                 switch(Config -> EmulationConfig -> Attributes[TEXTATTR_HIGHLIGHT])
  3324.                 {
  3325.                     case TEXTATTR_UNDERLINE:
  3326.  
  3327.                         Value |= ATTR_UNDERLINE;
  3328.                         break;
  3329.  
  3330.                     case TEXTATTR_HIGHLIGHT:
  3331.  
  3332.                         Value |= ATTR_HIGHLIGHT;
  3333.                         break;
  3334.  
  3335.                     case TEXTATTR_BLINK:
  3336.  
  3337.                         Value |= ATTR_BLINK;
  3338.                         break;
  3339.  
  3340.                     case TEXTATTR_INVERSE:
  3341.  
  3342.                         Value |= ATTR_INVERSE;
  3343.                         break;
  3344.                 }
  3345.             }
  3346.  
  3347.             if(i & ATTR_BLINK)
  3348.             {
  3349.                 switch(Config -> EmulationConfig -> Attributes[TEXTATTR_BLINK])
  3350.                 {
  3351.                     case TEXTATTR_UNDERLINE:
  3352.  
  3353.                         Value |= ATTR_UNDERLINE;
  3354.                         break;
  3355.  
  3356.                     case TEXTATTR_HIGHLIGHT:
  3357.  
  3358.                         Value |= ATTR_HIGHLIGHT;
  3359.                         break;
  3360.  
  3361.                     case TEXTATTR_BLINK:
  3362.  
  3363.                         Value |= ATTR_BLINK;
  3364.                         break;
  3365.  
  3366.                     case TEXTATTR_INVERSE:
  3367.  
  3368.                         Value |= ATTR_INVERSE;
  3369.                         break;
  3370.                 }
  3371.             }
  3372.  
  3373.             if(i & ATTR_INVERSE)
  3374.             {
  3375.                 switch(Config -> EmulationConfig -> Attributes[TEXTATTR_INVERSE])
  3376.                 {
  3377.                     case TEXTATTR_UNDERLINE:
  3378.  
  3379.                         Value |= ATTR_UNDERLINE;
  3380.                         break;
  3381.  
  3382.                     case TEXTATTR_HIGHLIGHT:
  3383.  
  3384.                         Value |= ATTR_HIGHLIGHT;
  3385.                         break;
  3386.  
  3387.                     case TEXTATTR_BLINK:
  3388.  
  3389.                         Value |= ATTR_BLINK;
  3390.                         break;
  3391.  
  3392.                     case TEXTATTR_INVERSE:
  3393.  
  3394.                         Value |= ATTR_INVERSE;
  3395.                         break;
  3396.                 }
  3397.             }
  3398.  
  3399.             TextAttributeTable[i] = Value;
  3400.         }
  3401.     }
  3402.  
  3403.         /* Determine window inner dimensions and top/left edge offsets. */
  3404.  
  3405.     UpdateTerminalLimits();
  3406.  
  3407.         /* Set up scaling data (bitmaps & rastports). */
  3408.  
  3409.     if(!CreateScale(Window))
  3410.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_FONT_SCALING_INFO_TXT));
  3411.  
  3412.     if(!CreateOffsetTables())
  3413.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_OFFSET_TABLES_TXT));
  3414.  
  3415.     TabStopMax = Window -> WScreen -> Width / TextFontWidth;
  3416.  
  3417.         /* Allocate the tab stop line. */
  3418.  
  3419.     if(!(TabStops = (BYTE *)AllocVecPooled(TabStopMax,MEMF_ANY | MEMF_CLEAR)))
  3420.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  3421.  
  3422.         /* Push it on the window stack (should become bottommost
  3423.          * entry).
  3424.          */
  3425.  
  3426.     PushWindow(Window);
  3427.  
  3428.     if(TermPort)
  3429.         TermPort -> TopWindow = Window;
  3430.  
  3431.     if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED && Config -> ScreenConfig -> SplitStatus)
  3432.     {
  3433.         if(!(StatusWindow = OpenWindowTags(NULL,
  3434.             WA_Top,            Window -> TopEdge + Window -> Height,
  3435.             WA_Left,        Window -> LeftEdge,
  3436.             WA_InnerWidth,        StatusWidth,
  3437.             WA_InnerHeight,        StatusHeight,
  3438.             WA_DragBar,        TRUE,
  3439.             WA_DepthGadget,        TRUE,
  3440.             WA_NewLookMenus,    TRUE,
  3441.             WA_Title,        ScreenTitle,
  3442.             WA_CustomScreen,    Window -> WScreen,
  3443.             WA_RMBTrap,        TRUE,
  3444.             WA_CloseGadget,        TRUE,
  3445.             WA_MenuHelp,        TRUE,
  3446.  
  3447.             AmigaGlyph ? WA_AmigaKey  : TAG_IGNORE, AmigaGlyph,
  3448.             CheckGlyph ? WA_Checkmark : TAG_IGNORE, CheckGlyph,
  3449.         TAG_DONE)))
  3450.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_STATUS_WINDOW_TXT));
  3451.     }
  3452.     else
  3453.         StatusWindow = NULL;
  3454.  
  3455.     if(StatusWindow)
  3456.     {
  3457.         StatusWindow -> UserPort = Window -> UserPort;
  3458.  
  3459.         ModifyIDCMP(StatusWindow,Window -> IDCMPFlags);
  3460.     }
  3461.  
  3462.     UpdateTerminalLimits();
  3463.  
  3464.     RPort = Window -> RPort;
  3465.  
  3466.         /* Default console setup. */
  3467.  
  3468.     CursorX = 0;
  3469.     CursorY    = 0;
  3470.  
  3471.     SetDrMd(RPort,JAM2);
  3472.  
  3473.         /* Set the font. */
  3474.  
  3475.     SetFont(RPort,CurrentFont);
  3476.  
  3477.         /* Redirect AmigaDOS requesters. */
  3478.  
  3479.     OldWindowPtr = ThisProcess -> pr_WindowPtr;
  3480.  
  3481.     ThisProcess -> pr_WindowPtr = (APTR)Window;
  3482.  
  3483.         /* Create the character raster. */
  3484.  
  3485.     if(!CreateRaster())
  3486.         return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_SCREEN_RASTER_TXT));
  3487.  
  3488.     ConOutputUpdate();
  3489.  
  3490.     ConFontScaleUpdate();
  3491.  
  3492.         /* Set up the scrolling info. */
  3493.  
  3494.     ScrollLineCount = Window -> WScreen -> Height / TextFontHeight;
  3495.  
  3496.     if(!(ScrollLines = (struct ScrollLineInfo *)AllocVecPooled(sizeof(struct ScrollLineInfo) * ScrollLineCount,MEMF_ANY|MEMF_CLEAR)))
  3497.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_SCROLLING_SUPPORT_INFO_TXT));
  3498.  
  3499.         /* Create the menu strip. */
  3500.  
  3501.     if(Error = BuildMenu())
  3502.         return(Error);
  3503.  
  3504.         /* Disable the `Execute ARexx Command' menu item if
  3505.          * the rexx server is not available.
  3506.          */
  3507.  
  3508.     if(!RexxSysBase)
  3509.         OffItem(MEN_EXECUTE_REXX_COMMAND);
  3510.  
  3511.     if(Recording)
  3512.     {
  3513.         OnItem(MEN_RECORD_LINE);
  3514.  
  3515.         CheckItem(MEN_RECORD,TRUE);
  3516.         CheckItem(MEN_RECORD_LINE,RecordingLine);
  3517.     }
  3518.     else
  3519.     {
  3520.         OffItem(MEN_RECORD_LINE);
  3521.  
  3522.         CheckItem(MEN_RECORD,FALSE);
  3523.         CheckItem(MEN_RECORD_LINE,FALSE);
  3524.     }
  3525.  
  3526.     CheckItem(MEN_DISABLE_TRAPS,!(WatchTraps && GenericListTable[GLIST_TRAP] -> ListHeader . mlh_Head -> mln_Succ));
  3527.  
  3528.     if(StatusWindow)
  3529.     {
  3530.         SetMenuStrip(StatusWindow,Menu);
  3531.  
  3532.         StatusWindow -> Flags &= ~WFLG_RMBTRAP;
  3533.  
  3534.         SetDrMd(StatusWindow -> RPort,JAM2);
  3535.     }
  3536.  
  3537.         /* Add a tick if file capture is active. */
  3538.  
  3539.     if(FileCapture)
  3540.         CheckItem(MEN_CAPTURE_TO_FILE,TRUE);
  3541.     else
  3542.         CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  3543.  
  3544.         /* Add a tick if printer capture is active. */
  3545.  
  3546.     CheckItem(MEN_CAPTURE_TO_PRINTER,PrinterCapture != NULL);
  3547.  
  3548.         /* Add a tick if the buffer is frozen. */
  3549.  
  3550.     CheckItem(MEN_FREEZE_BUFFER,BufferFrozen);
  3551.  
  3552.         /* Disable the dialing functions if online. */
  3553.  
  3554.     ObtainSemaphore(&OnlineSemaphore);
  3555.  
  3556.     if(Online)
  3557.         SetDialMenu(FALSE);
  3558.     else
  3559.         SetDialMenu(TRUE);
  3560.  
  3561.     ReleaseSemaphore(&OnlineSemaphore);
  3562.  
  3563.         /* Take care of the chat line. */
  3564.  
  3565.     if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0])
  3566.         OffItem(MEN_CHAT_LINE);
  3567.     else
  3568.         CheckItem(MEN_CHAT_LINE,ChatMode);
  3569.  
  3570.         /* Update the clipboard menus. */
  3571.  
  3572.     SetClipMenu(FALSE);
  3573.  
  3574.     if(!XProtocolBase)
  3575.         SetTransferMenu(FALSE);
  3576.  
  3577.         /* Disable the `Print Screen' and `Save ASCII' functions
  3578.          * if raster is not enabled.
  3579.          */
  3580.  
  3581.     SetRasterMenu(RasterEnabled);
  3582.  
  3583.         /* Enable the menu. */
  3584.  
  3585.     Window -> Flags &= ~WFLG_RMBTRAP;
  3586.  
  3587.     strcpy(EmulationName,LocaleString(MSG_TERMXEM_NO_EMULATION_TXT));
  3588.  
  3589.         /* Create the status server. */
  3590.  
  3591.     Forbid();
  3592.  
  3593.     if(StatusProcess = CreateNewProcTags(
  3594.         NP_Entry,    StatusServer,
  3595.         NP_Name,    "term Status Process",
  3596.         NP_WindowPtr,    -1,
  3597.         NP_Priority,    5,
  3598.     TAG_DONE))
  3599.     {
  3600.         ClrSignal(SIG_HANDSHAKE);
  3601.  
  3602.         Wait(SIG_HANDSHAKE);
  3603.     }
  3604.  
  3605.     Permit();
  3606.  
  3607.         /* Status server has `died'. */
  3608.  
  3609.     if(!StatusProcess)
  3610.         return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_STATUS_TASK_TXT));
  3611.  
  3612.         /* Obtain the default public screen name just in case
  3613.          * we'll need it later.
  3614.          */
  3615.  
  3616.     GetDefaultPubScreen(DefaultPubScreenName);
  3617.  
  3618.         /* Set up the window size. */
  3619.  
  3620.     ScreenSizeStuff();
  3621.  
  3622.         /* Select the default console data processing routine. */
  3623.  
  3624.     Forbid();
  3625.  
  3626.     ConProcessData = ConProcessData8;
  3627.  
  3628.     Permit();
  3629.  
  3630.         /* Handle the remaining terminal setup. */
  3631.  
  3632.     if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0])
  3633.     {
  3634.         if(!OpenEmulator(Config -> TerminalConfig -> EmulationFileName))
  3635.         {
  3636.             Config -> TerminalConfig -> EmulationMode = EMULATION_ANSIVT100;
  3637.  
  3638.             ResetDisplay = TRUE;
  3639.  
  3640.             RasterEnabled = TRUE;
  3641.  
  3642.             MyEasyRequest(Window,LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_EMULATION_LIBRARY_TXT),Config -> TerminalConfig -> EmulationFileName);
  3643.         }
  3644.         else
  3645.         {
  3646.             if(RasterEnabled)
  3647.                 RasterEnabled = FALSE;
  3648.  
  3649.             SetRasterMenu(RasterEnabled);
  3650.         }
  3651.     }
  3652.  
  3653.         /* Choose the right console data processing routine. */
  3654.  
  3655.     ConProcessUpdate();
  3656.  
  3657.         /* Reset terminal emulation. */
  3658.  
  3659.     if(Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  3660.     {
  3661.         ClearCursor();
  3662.  
  3663.         ForegroundPen = GetPenIndex(SafeTextPen);
  3664.         BackgroundPen = 0;
  3665.  
  3666.         UpdatePens();
  3667.  
  3668.         Reset();
  3669.  
  3670.         DrawCursor();
  3671.     }
  3672.     else
  3673.     {
  3674.         if(XEmulatorBase)
  3675.             XEmulatorResetConsole(XEM_IO);
  3676.     }
  3677.  
  3678.         /* Restart the fast! macro panel. */
  3679.  
  3680.     if(HadFastMacros || Config -> MiscConfig -> OpenFastMacroPanel)
  3681.         OpenFastWindow();
  3682.  
  3683.     if(Config -> TerminalConfig -> UseTerminalTask && Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  3684.         CreateEmulationProcess();
  3685.     else
  3686.         DeleteEmulationProcess();
  3687.  
  3688.     CreateLED();
  3689.  
  3690.     TTYResize();
  3691.  
  3692.     return(NULL);
  3693. }
  3694.  
  3695.     /* CloseAll():
  3696.      *
  3697.      *    Free all resources and leave the program.
  3698.      */
  3699.  
  3700. VOID __regargs
  3701. CloseAll(BYTE CloseDOS)
  3702. {
  3703.     WORD i;
  3704.  
  3705.     Forbid();
  3706.  
  3707.     if(RendezvousSemaphore . rs_Semaphore . ss_Link . ln_Name)
  3708.         RemSemaphore(&RendezvousSemaphore);
  3709.  
  3710.     Permit();
  3711.  
  3712. #ifdef DATAFEED
  3713.     {
  3714.         extern BPTR DataFeed;
  3715.  
  3716.         if(DataFeed)
  3717.         {
  3718.             Close(DataFeed);
  3719.  
  3720.             DataFeed = NULL;
  3721.         }
  3722.     }
  3723. #endif    /* DATAFEED */
  3724.  
  3725.     Forbid();
  3726.  
  3727.     if(DialMsg)
  3728.     {
  3729.         DialMsg -> rm_Result1 = RC_WARN;
  3730.         DialMsg -> rm_Result2 = 0;
  3731.  
  3732.         ReplyMsg(DialMsg);
  3733.  
  3734.         DialMsg = NULL;
  3735.     }
  3736.  
  3737.     Permit();
  3738.  
  3739.     DeleteRecord();
  3740.  
  3741.     DeleteQueueProcess();
  3742.  
  3743.     SoundExit();
  3744.  
  3745.     SZ_SizeCleanup();
  3746.  
  3747.     FreeDialList(TRUE);
  3748.  
  3749.     if(SpecialQueue)
  3750.     {
  3751.         DeleteMsgQueue(SpecialQueue);
  3752.  
  3753.         SpecialQueue = NULL;
  3754.     }
  3755.  
  3756.     if(SpecialTable)
  3757.     {
  3758.         FreeVecPooled(SpecialTable);
  3759.  
  3760.         SpecialTable = NULL;
  3761.     }
  3762.  
  3763.     if(AbortTable)
  3764.     {
  3765.         FreeVecPooled(AbortTable);
  3766.  
  3767.         AbortTable = NULL;
  3768.     }
  3769.  
  3770.     if(BackupConfig)
  3771.     {
  3772.         DeleteConfiguration(BackupConfig);
  3773.  
  3774.         BackupConfig = NULL;
  3775.     }
  3776.  
  3777.     if(IntuitionBase && Window)
  3778.         BlockWindows();
  3779.  
  3780.     /* ALWAYS */
  3781.     {
  3782.         extern struct MsgPort *RexxPort;
  3783.  
  3784.         if(RexxPort)
  3785.             RemPort(RexxPort);
  3786.     }
  3787.  
  3788.     if(EditList)
  3789.     {
  3790.         DeleteList(EditList);
  3791.  
  3792.         EditList = NULL;
  3793.     }
  3794.  
  3795.     if(EditLabels)
  3796.     {
  3797.         FreeVecPooled(EditLabels);
  3798.  
  3799.         EditLabels = NULL;
  3800.     }
  3801.  
  3802.     DeleteChatGadget();
  3803.  
  3804.     if(TermRexxPort)
  3805.     {
  3806.         if(RexxSysBase)
  3807.         {
  3808.             struct Message *Msg;
  3809.  
  3810.             while(Msg = GetMsg(TermRexxPort))
  3811.                 ReplyMsg(Msg);
  3812.         }
  3813.  
  3814.         DeleteMsgPort(TermRexxPort);
  3815.  
  3816.         TermRexxPort = NULL;
  3817.     }
  3818.  
  3819.     if(RexxProcess)
  3820.     {
  3821.         Forbid();
  3822.  
  3823.         Signal(RexxProcess,SIG_KILL);
  3824.  
  3825.         ClrSignal(SIG_HANDSHAKE);
  3826.  
  3827.         Wait(SIG_HANDSHAKE);
  3828.  
  3829.         Permit();
  3830.  
  3831.         RexxProcess = NULL;
  3832.     }
  3833.  
  3834.     if(RexxSysBase)
  3835.     {
  3836.         CloseLibrary(RexxSysBase);
  3837.  
  3838.         RexxSysBase = NULL;
  3839.     }
  3840.  
  3841.     if(XprIO && XProtocolBase)
  3842.         XProtocolCleanup(XprIO);
  3843.  
  3844.     if(XProtocolBase)
  3845.     {
  3846.         CloseLibrary(XProtocolBase);
  3847.  
  3848.         XProtocolBase = NULL;
  3849.     }
  3850.  
  3851.     if(XprIO)
  3852.     {
  3853.         FreeVec(XprIO);
  3854.  
  3855.         XprIO = NULL;
  3856.     }
  3857.  
  3858.     if(CursorKeys)
  3859.     {
  3860.         FreeVecPooled(CursorKeys);
  3861.  
  3862.         CursorKeys = NULL;
  3863.     }
  3864.  
  3865.     if(MacroKeys)
  3866.     {
  3867.         FreeVecPooled(MacroKeys);
  3868.  
  3869.         MacroKeys = NULL;
  3870.     }
  3871.  
  3872.     FreeList(&ARexxQueue);
  3873.  
  3874.     TerminateBuffer();
  3875.  
  3876.     DeleteSpeech();
  3877.  
  3878.     Forbid();
  3879.  
  3880.     BufferClosed = TRUE;
  3881.  
  3882.     DeleteBuffer();
  3883.  
  3884.     Permit();
  3885.  
  3886.     if(AttentionBuffers[0])
  3887.     {
  3888.         FreeVecPooled(AttentionBuffers[0]);
  3889.  
  3890.         AttentionBuffers[0] = NULL;
  3891.     }
  3892.  
  3893.     if(SendTable)
  3894.     {
  3895.         FreeTranslationTable(SendTable);
  3896.  
  3897.         SendTable = NULL;
  3898.     }
  3899.  
  3900.     if(ReceiveTable)
  3901.     {
  3902.         FreeTranslationTable(ReceiveTable);
  3903.  
  3904.         ReceiveTable = NULL;
  3905.     }
  3906.  
  3907.     FreeDialList(TRUE);
  3908.  
  3909.     DeleteOffsetTables();
  3910.  
  3911.     FreeList(&FastMacroList);
  3912.     FreeList((struct List *)&ReviewBufferHistory);
  3913.     FreeList((struct List *)&TextBufferHistory);
  3914.  
  3915.     for(i = GLIST_UPLOAD ; i < GLIST_COUNT ; i++)
  3916.     {
  3917.         if(GenericListTable[i])
  3918.         {
  3919.             DeleteGenericList(GenericListTable[i]);
  3920.  
  3921.             GenericListTable[i] = NULL;
  3922.         }
  3923.     }
  3924.  
  3925.     if(FileCapture)
  3926.     {
  3927.         BufferClose(FileCapture);
  3928.  
  3929.         if(!GetFileSize(CaptureName))
  3930.             DeleteFile(CaptureName);
  3931.         else
  3932.         {
  3933.             AddProtection(CaptureName,FIBF_EXECUTE);
  3934.  
  3935.             if(Config -> MiscConfig -> CreateIcons)
  3936.                 AddIcon(CaptureName,FILETYPE_TEXT,FALSE);
  3937.         }
  3938.  
  3939.         FileCapture = NULL;
  3940.     }
  3941.  
  3942.     if(PrinterCapture)
  3943.     {
  3944.         Close(PrinterCapture);
  3945.  
  3946.         PrinterCapture = NULL;
  3947.     }
  3948.  
  3949.         /* Close the external emulator. */
  3950.  
  3951.     if(XEmulatorBase)
  3952.     {
  3953.         if(XEM_IO)
  3954.         {
  3955.             XEmulatorMacroKeyFilter(XEM_IO,NULL);
  3956.             XEmulatorCloseConsole(XEM_IO);
  3957.             XEmulatorCleanup(XEM_IO);
  3958.  
  3959.             FreeVec(XEM_IO);
  3960.  
  3961.             XEM_IO = NULL;
  3962.         }
  3963.  
  3964.         CloseLibrary(XEmulatorBase);
  3965.  
  3966.         XEmulatorBase = NULL;
  3967.     }
  3968.  
  3969.     if(XEM_MacroKeys)
  3970.     {
  3971.         FreeVecPooled(XEM_MacroKeys);
  3972.  
  3973.         XEM_MacroKeys = NULL;
  3974.     }
  3975.  
  3976.     DeleteDisplay();
  3977.  
  3978.     CaptureParserExit();
  3979.  
  3980.     if(KeySegment)
  3981.     {
  3982.         UnLoadSeg(KeySegment);
  3983.  
  3984.         KeySegment = NULL;
  3985.     }
  3986.  
  3987.     StopCall(TRUE);
  3988.  
  3989.     if(CheckBit != -1)
  3990.     {
  3991.         FreeSignal(CheckBit);
  3992.  
  3993.         CheckBit = -1;
  3994.     }
  3995.  
  3996.     ClearSerial();
  3997.  
  3998.     DeleteSerial();
  3999.  
  4000.     DeletePatternList(PatternList);
  4001.  
  4002.     if(TimeRequest)
  4003.     {
  4004.         if(TimeRequest -> tr_node . io_Device)
  4005.             CloseDevice(TimeRequest);
  4006.  
  4007.         DeleteIORequest(TimeRequest);
  4008.  
  4009.         TimeRequest = NULL;
  4010.     }
  4011.  
  4012.     if(TimePort)
  4013.     {
  4014.         DeleteMsgPort(TimePort);
  4015.  
  4016.         TimePort = NULL;
  4017.     }
  4018.  
  4019.     ShutdownCx();
  4020.  
  4021.     if(NormalColourTable)
  4022.     {
  4023.         DeleteColourTable(NormalColourTable);
  4024.  
  4025.         NormalColourTable = NULL;
  4026.     }
  4027.  
  4028.     if(BlinkColourTable)
  4029.     {
  4030.         DeleteColourTable(BlinkColourTable);
  4031.  
  4032.         BlinkColourTable = NULL;
  4033.     }
  4034.  
  4035.     if(ANSIColourTable)
  4036.     {
  4037.         DeleteColourTable(ANSIColourTable);
  4038.  
  4039.         ANSIColourTable = NULL;
  4040.     }
  4041.  
  4042.     if(EGAColourTable)
  4043.     {
  4044.         DeleteColourTable(EGAColourTable);
  4045.  
  4046.         EGAColourTable = NULL;
  4047.     }
  4048.  
  4049.     if(DefaultColourTable)
  4050.     {
  4051.         DeleteColourTable(DefaultColourTable);
  4052.  
  4053.         DefaultColourTable = NULL;
  4054.     }
  4055.  
  4056.     if(MonoColourTable)
  4057.     {
  4058.         DeleteColourTable(MonoColourTable);
  4059.  
  4060.         MonoColourTable = NULL;
  4061.     }
  4062.  
  4063.     if(TermPort)
  4064.     {
  4065.         if(TermID != -1)
  4066.         {
  4067.             ObtainSemaphore(&TermPort -> OpenSemaphore);
  4068.  
  4069.             TermPort -> OpenCount--;
  4070.  
  4071.             if(TermPort -> OpenCount <= 0 && !TermPort -> HoldIt)
  4072.             {
  4073.                 RemPort(&TermPort -> ExecNode);
  4074.  
  4075.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  4076.  
  4077.                 FreeVec(TermPort);
  4078.             }
  4079.             else
  4080.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  4081.  
  4082.             TermID = -1;
  4083.         }
  4084.  
  4085.         TermPort = NULL;
  4086.     }
  4087.  
  4088.     CloseClip();
  4089.  
  4090.     if(GTLayoutBase)
  4091.     {
  4092.         CloseLibrary(GTLayoutBase);
  4093.  
  4094.         GTLayoutBase = NULL;
  4095.     }
  4096.  
  4097.     if(Config)
  4098.     {
  4099.         DeleteConfiguration(Config);
  4100.  
  4101.         Config = NULL;
  4102.     }
  4103.  
  4104.     if(PrivateConfig)
  4105.     {
  4106.         DeleteConfiguration(PrivateConfig);
  4107.  
  4108.         PrivateConfig = NULL;
  4109.     }
  4110.  
  4111.     if(FakeInputEvent)
  4112.     {
  4113.         FreeVecPooled(FakeInputEvent);
  4114.  
  4115.         FakeInputEvent = NULL;
  4116.     }
  4117.  
  4118.     if(ConsoleDevice)
  4119.     {
  4120.         CloseDevice(ConsoleRequest);
  4121.  
  4122.         ConsoleDevice = NULL;
  4123.     }
  4124.  
  4125.     if(ConsoleRequest)
  4126.     {
  4127.         FreeVecPooled(ConsoleRequest);
  4128.  
  4129.         ConsoleRequest = NULL;
  4130.     }
  4131.  
  4132.     if(IconBase)
  4133.     {
  4134.         CloseLibrary(IconBase);
  4135.  
  4136.         IconBase = NULL;
  4137.     }
  4138.  
  4139.     if(DataTypesBase)
  4140.     {
  4141.         CloseLibrary(DataTypesBase);
  4142.  
  4143.         DataTypesBase = NULL;
  4144.     }
  4145.  
  4146.     if(WorkbenchBase)
  4147.     {
  4148.         CloseLibrary(WorkbenchBase);
  4149.  
  4150.         WorkbenchBase = NULL;
  4151.     }
  4152.  
  4153.     if(OwnDevUnitBase)
  4154.     {
  4155.         CloseLibrary(OwnDevUnitBase);
  4156.  
  4157.         OwnDevUnitBase = NULL;
  4158.     }
  4159.  
  4160.     if(CxBase)
  4161.     {
  4162.         CloseLibrary(CxBase);
  4163.  
  4164.         CxBase = NULL;
  4165.     }
  4166.  
  4167.     if(IFFParseBase)
  4168.     {
  4169.         CloseLibrary(IFFParseBase);
  4170.  
  4171.         IFFParseBase = NULL;
  4172.     }
  4173.  
  4174.     if(AslBase)
  4175.     {
  4176.         CloseLibrary(AslBase);
  4177.  
  4178.         AslBase = NULL;
  4179.     }
  4180.  
  4181.     if(DiskfontBase)
  4182.     {
  4183.         CloseLibrary(DiskfontBase);
  4184.  
  4185.         DiskfontBase = NULL;
  4186.     }
  4187.  
  4188.     if(GadToolsBase)
  4189.     {
  4190.         CloseLibrary(GadToolsBase);
  4191.  
  4192.         GadToolsBase = NULL;
  4193.     }
  4194.  
  4195.     if(LayersBase)
  4196.     {
  4197.         CloseLibrary(LayersBase);
  4198.  
  4199.         LayersBase = NULL;
  4200.     }
  4201.  
  4202.     if(GfxBase)
  4203.     {
  4204.         CloseLibrary(GfxBase);
  4205.  
  4206.         GfxBase = NULL;
  4207.     }
  4208.  
  4209.     if(IntuitionBase)
  4210.     {
  4211.         CloseLibrary(IntuitionBase);
  4212.  
  4213.         IntuitionBase = NULL;
  4214.     }
  4215.  
  4216.     LocaleClose();
  4217.  
  4218.     if(UtilityBase)
  4219.     {
  4220.         CloseLibrary(UtilityBase);
  4221.  
  4222.         UtilityBase = NULL;
  4223.     }
  4224.  
  4225. #ifdef DEBUG
  4226.     DebugExit();
  4227. #endif    /* DEBUG */
  4228.  
  4229.     MemoryCleanup();
  4230.  
  4231.     if(WBenchMsg)
  4232.     {
  4233.         CurrentDir(WBenchLock);
  4234.  
  4235.         if(DOSBase)
  4236.         {
  4237.             CloseLibrary(DOSBase);
  4238.  
  4239.             DOSBase = NULL;
  4240.         }
  4241.  
  4242.         Forbid();
  4243.  
  4244.         ReplyMsg((struct Message *)WBenchMsg);
  4245.  
  4246.         WBenchMsg = NULL;
  4247.     }
  4248.     else
  4249.     {
  4250.         if(CloseDOS && DOSBase)
  4251.         {
  4252.             CloseLibrary(DOSBase);
  4253.  
  4254.             DOSBase = NULL;
  4255.         }
  4256.     }
  4257. }
  4258.  
  4259.     /* AddExtraAssignment(STRPTR LocalDir,STRPTR Assign):
  4260.      *
  4261.      *    Add assignments for local directories.
  4262.      */
  4263.  
  4264. STATIC VOID __regargs
  4265. AddExtraAssignment(STRPTR LocalDir,STRPTR Assign)
  4266. {
  4267.     UBYTE    LocalBuffer[40];
  4268.     BPTR    FileLock;
  4269.  
  4270.         // Add the colon, we'll need it later
  4271.  
  4272.     SPrintf(LocalBuffer,"%s:",Assign);
  4273.  
  4274.         // Is the local directory present?
  4275.  
  4276.     if(FileLock = Lock(LocalDir,ACCESS_READ))
  4277.     {
  4278.             // Is the assignment present?
  4279.  
  4280.         if(IsAssign(LocalBuffer))
  4281.         {
  4282.                 // Check to see if the local directory
  4283.                 // is already on the assignment list
  4284.  
  4285.             if(LockInAssign(FileLock,LocalBuffer))
  4286.             {
  4287.                 UnLock(FileLock);
  4288.  
  4289.                 FileLock = NULL;
  4290.             }
  4291.         }
  4292.     }
  4293.  
  4294.         // Can we attach the lock to the assignment list?
  4295.  
  4296.     if(FileLock)
  4297.     {
  4298.         Forbid();
  4299.  
  4300.             // If the assignment is already present, add the
  4301.             // new directory, else create a new assignment.
  4302.  
  4303.         if(IsAssign(LocalBuffer))
  4304.             AssignAdd(Assign,FileLock);
  4305.         else
  4306.             AssignLock(Assign,FileLock);
  4307.  
  4308.         Permit();
  4309.     }
  4310. }
  4311.  
  4312.     /* OpenAll():
  4313.      *
  4314.      *    Open all required resources or return an error message
  4315.      *    if anything went wrong.
  4316.      */
  4317.  
  4318. STRPTR __regargs
  4319. OpenAll(STRPTR ConfigPath)
  4320. {
  4321.     extern    ULONG HookEntry(struct Hook *,APTR,APTR);
  4322.  
  4323.     UBYTE         PathBuffer[MAX_FILENAME_LENGTH];
  4324.     STRPTR         Result,Error,ConfigFileName = NULL;
  4325.     WORD         i;
  4326.     struct Node    *Node;
  4327.     LONG         ErrorCode;
  4328.  
  4329.         /* Pretty cheap ;-) */
  4330.  
  4331.     Kick30 = (SysBase -> LibNode . lib_Version >= 39);
  4332.  
  4333.     if(!MemorySetup())
  4334.         return("Cannot create memory pool");
  4335.  
  4336. #ifdef DEBUG
  4337.     DebugInit();
  4338. #endif    /* DEBUG */
  4339.  
  4340.         /* Don't let it hit the ground! */
  4341.  
  4342.     ConTransfer = ConProcess;
  4343.  
  4344.         /* Remember the start of this session. */
  4345.  
  4346.     DateStamp(&SessionStart);
  4347.  
  4348.         /* Reset some flags. */
  4349.  
  4350.     BinaryTransfer    = TRUE;
  4351.  
  4352.     Status        = STATUS_READY;
  4353.  
  4354.     WasOnline    = FALSE;
  4355.     Online        = FALSE;
  4356.  
  4357.     InSequence    = FALSE;
  4358.     Quiet        = FALSE;
  4359.  
  4360.     TagDPI[0] . ti_Tag = TAG_DONE;
  4361.  
  4362.         /* Double buffered file locking. */
  4363.  
  4364.     NewList(&DoubleBufferList);
  4365.  
  4366.     InitSemaphore(&DoubleBufferSemaphore);
  4367.  
  4368.         /* ARexx command queue. */
  4369.  
  4370.     InitSemaphore(&ARexxQueueSemaphore);
  4371.  
  4372.     NewList(&ARexxQueue);
  4373.  
  4374.         /* Terminal emulation data. */
  4375.  
  4376.     InitSemaphore(&TerminalSemaphore);
  4377.  
  4378.         /* Phone number patterns and rates. */
  4379.  
  4380.     InitSemaphore(&PatternSemaphore);
  4381.  
  4382.         /* Online status. */
  4383.  
  4384.     InitSemaphore(&OnlineSemaphore);
  4385.  
  4386.         /* Text buffer task access semaphore. */
  4387.  
  4388.     InitSemaphore(&BufferTaskSemaphore);
  4389.  
  4390.         /* Set up all the lists. */
  4391.  
  4392.     NewList(&PacketHistoryList);
  4393.     NewList(&EmptyList);
  4394.     NewList(&FastMacroList);
  4395.     NewList(&TransferInfoList);
  4396.  
  4397.     NewList((struct List *)&ReviewBufferHistory);
  4398.     NewList((struct List *)&TextBufferHistory);
  4399.  
  4400.         /* Rendezvous setup. */
  4401.  
  4402.     InitSemaphore(&RendezvousSemaphore);
  4403.  
  4404.     RendezvousSemaphore . rs_Login        = RendezvousLogin;
  4405.     RendezvousSemaphore . rs_Logoff        = RendezvousLogoff;
  4406.     RendezvousSemaphore . rs_NewNode    = RendezvousNewNode;
  4407.  
  4408.         /* Open the translation tables. */
  4409.  
  4410.     LocaleOpen("term.catalog","english",20);
  4411.  
  4412.         /* Fill in the menu configuration. */
  4413.  
  4414.     LocalizeMenuTable(TermMenu,MenuLabels);
  4415.  
  4416.         /* Open intuition.library, any version. */
  4417.  
  4418.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  4419.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_INTUITION_LIBRARY_TXT));
  4420.  
  4421.     Forbid();
  4422.  
  4423.         /* Query the current public screen modes. */
  4424.  
  4425.     PublicModes = SetPubScreenModes(NULL);
  4426.  
  4427.         /* Set them back. */
  4428.  
  4429.     SetPubScreenModes(PublicModes);
  4430.  
  4431.     Permit();
  4432.  
  4433.         /* Check if we should use the old style sliders. */
  4434.  
  4435.     if(GetVar("termoldsliders",PathBuffer,256,NULL) >= 0)
  4436.         SliderType = SLIDER_KIND;
  4437.     else
  4438.         SliderType = LEVEL_KIND;
  4439.  
  4440.         /* Open some more libraries. */
  4441.  
  4442.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0)))
  4443.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GRAPHICS_LIBRARY_TXT));
  4444.  
  4445.     if(!(LayersBase = OpenLibrary("layers.library",0)))
  4446.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_LAYERS_LIBRARY_TXT));
  4447.  
  4448.         /* Install the correct routines to query
  4449.          * the rendering colours and drawing mode.
  4450.          */
  4451.  
  4452.     if(!Kick30)
  4453.     {
  4454.         ReadAPen = OldGetAPen;
  4455.         ReadBPen = OldGetBPen;
  4456.         ReadDrMd = OldGetDrMd;
  4457.         SetMask = OldSetWrMsk;
  4458.     }
  4459.     else
  4460.     {
  4461.         ReadAPen = NewGetAPen;
  4462.         ReadBPen = NewGetBPen;
  4463.         ReadDrMd = NewGetDrMd;
  4464.         SetMask = NewSetWrMsk;
  4465.     }
  4466.  
  4467.         /* Check if locale.library has already installed the operating system
  4468.          * patches required for localization.
  4469.          */
  4470.  
  4471.     LanguageCheck();
  4472.  
  4473.         /* Open the remaining libraries. */
  4474.  
  4475.     if(!(GadToolsBase = OpenLibrary("gadtools.library",0)))
  4476.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GADTOOLS_LIBRARY_TXT));
  4477.  
  4478.     if(!(AslBase = OpenLibrary("asl.library",0)))
  4479.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_ASL_LIBRARY_TXT));
  4480.  
  4481.     if(!(IFFParseBase = OpenLibrary("iffparse.library",0)))
  4482.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_IFFPARSE_LIBRARY_TXT));
  4483.  
  4484.     if(!(CxBase = OpenLibrary("commodities.library",0)))
  4485.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_COMMODITIES_LIBRARY_TXT));
  4486.  
  4487.     if(!(DiskfontBase = (struct Library *)OpenLibrary("diskfont.library",0)))
  4488.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_DISKFONT_LIBRARY_TXT));
  4489.  
  4490.         /* User interface. */
  4491.  
  4492.     if(!(GTLayoutBase = SafeOpenLibrary("PROGDIR:gtlayout.library",9)))
  4493.     {
  4494.         if(!(GTLayoutBase = SafeOpenLibrary("gtlayout.library",9)))
  4495.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GTLAYOUT_LIBRARY_TXT));
  4496.     }
  4497.  
  4498.         /* Open OwnDevUnit.library, don't complain if it fails. */
  4499.  
  4500.     OwnDevUnitBase = OpenLibrary(ODU_NAME,0);
  4501.  
  4502.         /* Open workbench.library, don't complain if it fails. */
  4503.  
  4504.     WorkbenchBase = OpenLibrary("workbench.library",0);
  4505.  
  4506.         /* Open icon.library as well, don't complain if it fails either. */
  4507.  
  4508.     IconBase = OpenLibrary("icon.library",0);
  4509.  
  4510.         /* Try to open datatypes.library, just for the fun of it. */
  4511.  
  4512.     DataTypesBase = OpenLibrary("datatypes.library",39);
  4513.  
  4514.     if(!(ConsoleRequest = (struct IOStdReq *)AllocVecPooled(sizeof(struct IOStdReq),MEMF_ANY|MEMF_CLEAR)))
  4515.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_CONSOLE_REQUEST_TXT));
  4516.  
  4517.     if(OpenDevice("console.device",CONU_LIBRARY,ConsoleRequest,0))
  4518.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_CONSOLE_DEVICE_TXT));
  4519.  
  4520.     ConsoleDevice = &ConsoleRequest -> io_Device -> dd_Library;
  4521.  
  4522.     if(!(FakeInputEvent = (struct InputEvent *)AllocVecPooled(sizeof(struct InputEvent),MEMF_ANY|MEMF_CLEAR)))
  4523.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_INPUTEVENT_TXT));
  4524.  
  4525.     FakeInputEvent -> ie_Class = IECLASS_RAWKEY;
  4526.  
  4527.     if(!(MacroKeys = (struct MacroKeys *)AllocVecPooled(sizeof(struct MacroKeys),MEMF_ANY|MEMF_CLEAR)))
  4528.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_MACROKEYS_TXT));
  4529.  
  4530.     if(!(CursorKeys = (struct CursorKeys *)AllocVecPooled(sizeof(struct CursorKeys),MEMF_ANY|MEMF_CLEAR)))
  4531.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_CURSORKEYS_TXT));
  4532.  
  4533.     ResetCursorKeys(CursorKeys);
  4534.  
  4535.         /* Add extra assignments. */
  4536.  
  4537.     AddExtraAssignment("PROGDIR:Fonts","Fonts");
  4538.     AddExtraAssignment("Fonts","Fonts");
  4539.     AddExtraAssignment("PROGDIR:Libs","Libs");
  4540.     AddExtraAssignment("Libs","Libs");
  4541.  
  4542.         /* Set up the attention buffers. */
  4543.  
  4544.     if(!(AttentionBuffers[0] = (STRPTR)AllocVecPooled(SCAN_COUNT * 260,MEMF_ANY|MEMF_CLEAR)))
  4545.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_SEQUENCE_ATTENTION_INFO_TXT));
  4546.  
  4547.     for(i = 1 ; i < SCAN_COUNT ; i++)
  4548.         AttentionBuffers[i] = &AttentionBuffers[i - 1][260];
  4549.  
  4550.         /* Obtain the default environment storage
  4551.          * path.
  4552.          */
  4553.  
  4554.     if(!ConfigPath)
  4555.     {
  4556.         ConfigPath = PathBuffer;
  4557.  
  4558.         if(!GetEnvDOS("TERMCONFIGPATH",PathBuffer))
  4559.         {
  4560.             if(!GetEnvDOS("TERMPATH",PathBuffer))
  4561.             {
  4562.                 APTR LastPtr = ThisProcess -> pr_WindowPtr;
  4563.                 BPTR FileLock;
  4564.  
  4565.                 strcpy(PathBuffer,"TERM:config");
  4566.  
  4567.                 ThisProcess -> pr_WindowPtr = (APTR)-1;
  4568.  
  4569.                 if(FileLock = Lock("TERM:",ACCESS_READ))
  4570.                     UnLock(FileLock);
  4571.                 else
  4572.                 {
  4573.                     FileLock = DupLock(ThisProcess-> pr_HomeDir);
  4574.  
  4575.                         /* Create TERM: assignment referring to
  4576.                          * the directory `term' was loaded from.
  4577.                          */
  4578.  
  4579.                     if(!AssignLock("TERM",FileLock))
  4580.                         UnLock(FileLock);
  4581.                 }
  4582.  
  4583.                 if(!(FileLock = Lock(PathBuffer,ACCESS_READ)))
  4584.                     FileLock = CreateDir(PathBuffer);
  4585.  
  4586.                 if(FileLock)
  4587.                     UnLock(FileLock);
  4588.  
  4589.                 ThisProcess -> pr_WindowPtr = LastPtr;
  4590.             }
  4591.         }
  4592.     }
  4593.     else
  4594.     {
  4595.         if(GetFileSize(ConfigPath))
  4596.         {
  4597.             STRPTR Index;
  4598.  
  4599.             strcpy(PathBuffer,ConfigPath);
  4600.  
  4601.             Index = PathPart(PathBuffer);
  4602.  
  4603.             *Index = 0;
  4604.  
  4605.             ConfigFileName = ConfigPath;
  4606.  
  4607.             ConfigPath = PathBuffer;
  4608.         }
  4609.     }
  4610.  
  4611.         /* Check for proper assignment path if necessary. */
  4612.  
  4613.         if(!Strnicmp(ConfigPath,"TERM:",5))
  4614.         {
  4615.             APTR OldPtr = ThisProcess -> pr_WindowPtr;
  4616.             BPTR DirLock;
  4617.  
  4618.             /* Block dos requesters. */
  4619.  
  4620.             ThisProcess -> pr_WindowPtr = (APTR)-1;
  4621.  
  4622.             /* Try to get a lock on `TERM:' assignment. */
  4623.  
  4624.         if(DirLock = Lock("TERM:",ACCESS_READ))
  4625.             UnLock(DirLock);
  4626.         else
  4627.         {
  4628.                 /* Clone current directory lock. */
  4629.  
  4630.             DirLock = DupLock(ThisProcess-> pr_CurrentDir);
  4631.  
  4632.                 /* Create TERM: assignment referring to
  4633.                  * current directory.
  4634.                  */
  4635.  
  4636.             if(!AssignLock("TERM",DirLock))
  4637.                 UnLock(DirLock);
  4638.         }
  4639.  
  4640.         ThisProcess -> pr_WindowPtr = OldPtr;
  4641.         }
  4642.  
  4643.         /* Create proper path names. */
  4644.  
  4645.     if(ConfigFileName)
  4646.     {
  4647.         if(!GetFileSize(ConfigFileName))
  4648.             ConfigFileName = NULL;
  4649.     }
  4650.  
  4651.     if(!ConfigFileName)
  4652.     {
  4653.         strcpy(LastConfig,ConfigPath);
  4654.  
  4655.         AddPart(LastConfig,"term_preferences.iff",MAX_FILENAME_LENGTH);
  4656.  
  4657.         if(!GetFileSize(LastConfig))
  4658.         {
  4659.             strcpy(LastConfig,ConfigPath);
  4660.  
  4661.             AddPart(LastConfig,"term.prefs",MAX_FILENAME_LENGTH);
  4662.         }
  4663.     }
  4664.     else
  4665.         strcpy(LastConfig,ConfigFileName);
  4666.  
  4667.     strcpy(DefaultPubScreenName,"Workbench");
  4668.  
  4669.         /* Create both configuration buffers. */
  4670.  
  4671.     if(!(Config = CreateConfiguration(TRUE)))
  4672.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_PRIMARY_CONFIG_TXT));
  4673.  
  4674.     if(!(PrivateConfig = CreateConfiguration(TRUE)))
  4675.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_SECONDARY_CONFIG_TXT));
  4676.  
  4677.     ResetConfig(Config,ConfigPath);
  4678.  
  4679.         /* Read some more environment variables. */
  4680.  
  4681.     if(!WindowName[0])
  4682.     {
  4683.         if(!GetEnvDOS("TERMWINDOW",WindowName))
  4684.             strcpy(WindowName,"CON:0/11//100/term Output Window/CLOSE/SCREEN %s");
  4685.     }
  4686.  
  4687.     GetEnvDOS("EDITOR",Config -> PathConfig -> Editor);
  4688.  
  4689.         /* Look for the default configuration file. */
  4690.  
  4691.     if(!ReadConfig(LastConfig,Config))
  4692.     {
  4693.         ResetConfig(Config,ConfigPath);
  4694.  
  4695.         Initializing = TRUE;
  4696.  
  4697.         LoadColours = TRUE;
  4698.  
  4699.             // Now we can safely assume that this is the
  4700.             // first invocation of this program on the
  4701.             // current setup
  4702.  
  4703.         FirstInvocation = TRUE;
  4704.     }
  4705.     else
  4706.     {
  4707.         Current2DefaultPalette(Config);
  4708.  
  4709.         if(Config -> ScreenConfig -> ColourMode == COLOUR_AMIGA)
  4710.             Initializing = FALSE;
  4711.         else
  4712.             Initializing = TRUE;
  4713.     }
  4714.  
  4715.     if(UseNewDevice)
  4716.         strcpy(Config -> SerialConfig -> SerialDevice,NewDevice);
  4717.  
  4718.     if(UseNewUnit)
  4719.         Config -> SerialConfig -> UnitNumber = NewUnit;
  4720.  
  4721.     if(Config -> MiscConfig -> OpenFastMacroPanel)
  4722.         HadFastMacros = TRUE;
  4723.  
  4724.     strcpy(LastPhone,    Config -> PathConfig -> DefaultStorage);
  4725.     AddPart(LastPhone,    "term_phonebook.iff",MAX_FILENAME_LENGTH);
  4726.  
  4727.     if(!GetFileSize(LastPhone))
  4728.     {
  4729.         strcpy(LastPhone,    Config -> PathConfig -> DefaultStorage);
  4730.         AddPart(LastPhone,    "phonebook.prefs",MAX_FILENAME_LENGTH);
  4731.     }
  4732.  
  4733.     strcpy(LastKeys,    Config -> PathConfig -> DefaultStorage);
  4734.     AddPart(LastKeys,    "term_hotkeys.iff",MAX_FILENAME_LENGTH);
  4735.  
  4736.     if(!GetFileSize(LastKeys))
  4737.     {
  4738.         strcpy(LastKeys,    Config -> PathConfig -> DefaultStorage);
  4739.         AddPart(LastKeys,    "hotkeys.prefs",MAX_FILENAME_LENGTH);
  4740.     }
  4741.  
  4742.     strcpy(LastSpeech,    Config -> PathConfig -> DefaultStorage);
  4743.     AddPart(LastSpeech,    "term_speech.iff",MAX_FILENAME_LENGTH);
  4744.  
  4745.     if(!GetFileSize(LastSpeech))
  4746.     {
  4747.         strcpy(LastSpeech,    Config -> PathConfig -> DefaultStorage);
  4748.         AddPart(LastSpeech,    "speech.prefs",MAX_FILENAME_LENGTH);
  4749.     }
  4750.  
  4751.     strcpy(LastFastMacros,    Config -> PathConfig -> DefaultStorage);
  4752.     AddPart(LastFastMacros,    "term_fastmacros.iff",MAX_FILENAME_LENGTH);
  4753.  
  4754.     if(!GetFileSize(LastFastMacros))
  4755.     {
  4756.         strcpy(LastFastMacros,    Config -> PathConfig -> DefaultStorage);
  4757.         AddPart(LastFastMacros,    "fastmacros.prefs",MAX_FILENAME_LENGTH);
  4758.     }
  4759.  
  4760.     if(Config -> FileConfig -> MacroFileName[0])
  4761.         strcpy(LastMacros,Config -> FileConfig -> MacroFileName);
  4762.     else
  4763.     {
  4764.         strcpy(LastMacros,    Config -> PathConfig -> DefaultStorage);
  4765.         AddPart(LastMacros,    "term_macros.iff",MAX_FILENAME_LENGTH);
  4766.  
  4767.         if(!GetFileSize(LastMacros))
  4768.         {
  4769.             strcpy(LastMacros,    Config -> PathConfig -> DefaultStorage);
  4770.             AddPart(LastMacros,    "macros.prefs",MAX_FILENAME_LENGTH);
  4771.  
  4772.             if(!GetFileSize(LastMacros))
  4773.             {
  4774.                 strcpy(LastMacros,    Config -> PathConfig -> DefaultStorage);
  4775.                 AddPart(LastMacros,    "functionkeys.prefs",MAX_FILENAME_LENGTH);
  4776.             }
  4777.         }
  4778.     }
  4779.  
  4780.         /* Load the keyboard macros. */
  4781.  
  4782.     if(!LoadMacros(LastMacros,MacroKeys))
  4783.         ResetMacroKeys(MacroKeys);
  4784.  
  4785.     if(Config -> FileConfig -> CursorFileName[0])
  4786.         strcpy(LastCursorKeys,Config -> FileConfig -> CursorFileName);
  4787.     else
  4788.     {
  4789.         strcpy(LastCursorKeys,    Config -> PathConfig -> DefaultStorage);
  4790.         AddPart(LastCursorKeys,    "cursorkeys.prefs",MAX_FILENAME_LENGTH);
  4791.     }
  4792.  
  4793.         /* Load the cursor keys. */
  4794.  
  4795.     if(!ReadIFFData(LastCursorKeys,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  4796.         ResetCursorKeys(CursorKeys);
  4797.  
  4798.     strcpy(LastSound,    Config -> PathConfig -> DefaultStorage);
  4799.     AddPart(LastSound,    "sound.prefs",MAX_FILENAME_LENGTH);
  4800.  
  4801.         /* Load the sound settings. */
  4802.  
  4803.     memset(&SoundConfig,0,sizeof(struct SoundConfig));
  4804.  
  4805.     SoundConfig . Volume = 100;
  4806.  
  4807.     if(!ReadIFFData(LastSound,&SoundConfig,sizeof(struct SoundConfig),ID_SOUN))
  4808.         strcpy(SoundConfig . BellFile,Config -> TerminalConfig -> BeepFileName);
  4809.  
  4810.         /* Initialize the sound support routines. */
  4811.  
  4812.     SoundInit();
  4813.  
  4814.         /* Load the phone number pattern / rates settings. */
  4815.  
  4816.     strcpy(LastPattern,    Config -> PathConfig -> DefaultStorage);
  4817.     AddPart(LastPattern,    "rates.prefs",MAX_FILENAME_LENGTH);
  4818.  
  4819.     if(!(PatternList = LoadTimeDateList(LastPattern,&ErrorCode)))
  4820.     {
  4821.         if(!(PatternList = (struct List *)AllocVecPooled(sizeof(struct List),MEMF_ANY)))
  4822.             return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4823.         else
  4824.             NewList(PatternList);
  4825.     }
  4826.  
  4827.         /* Are we to load the translation tables? */
  4828.  
  4829.     strcpy(LastTranslation,Config -> FileConfig -> TranslationFileName);
  4830.  
  4831.     if(Config -> FileConfig -> TranslationFileName[0])
  4832.     {
  4833.         if(SendTable = AllocTranslationTable())
  4834.         {
  4835.             if(ReceiveTable = AllocTranslationTable())
  4836.             {
  4837.                 if(!LoadTranslationTables(Config -> FileConfig -> TranslationFileName,SendTable,ReceiveTable))
  4838.                 {
  4839.                     FreeTranslationTable(SendTable);
  4840.  
  4841.                     SendTable = NULL;
  4842.  
  4843.                     FreeTranslationTable(ReceiveTable);
  4844.  
  4845.                     ReceiveTable = NULL;
  4846.                 }
  4847.                 else
  4848.                 {
  4849.                     if(IsStandardTable(SendTable) && IsStandardTable(ReceiveTable))
  4850.                     {
  4851.                         FreeTranslationTable(SendTable);
  4852.  
  4853.                         SendTable = NULL;
  4854.  
  4855.                         FreeTranslationTable(ReceiveTable);
  4856.  
  4857.                         ReceiveTable = NULL;
  4858.                     }
  4859.                 }
  4860.             }
  4861.             else
  4862.             {
  4863.                 FreeTranslationTable(SendTable);
  4864.  
  4865.                 SendTable = NULL;
  4866.             }
  4867.         }
  4868.     }
  4869.  
  4870.     SendSetup();
  4871.  
  4872.         /* Set up the capture parser. */
  4873.  
  4874.     if(!CaptureParserInit())
  4875.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4876.  
  4877.     ConOutputUpdate();
  4878.  
  4879.         /* Load the fast! macro settings. */
  4880.  
  4881.     LoadFastMacros(LastFastMacros,&FastMacroList);
  4882.  
  4883.         /* Load the speech settings. */
  4884.  
  4885.     if(!ReadIFFData(LastSpeech,&SpeechConfig,sizeof(struct SpeechConfig),ID_SPEK))
  4886.     {
  4887.         SpeechConfig . Rate        = DEFRATE;
  4888.         SpeechConfig . Pitch        = DEFPITCH;
  4889.         SpeechConfig . Frequency    = DEFFREQ;
  4890.         SpeechConfig . Volume        = DEFVOL;
  4891.         SpeechConfig . Sex        = DEFSEX;
  4892.         SpeechConfig . Enabled        = FALSE;
  4893.     }
  4894.  
  4895.         /* Load the hotkey settings. */
  4896.  
  4897.     if(!LoadHotkeys(LastKeys,&Hotkeys))
  4898.     {
  4899.         strcpy(Hotkeys . termScreenToFront,    "lshift rshift return");
  4900.         strcpy(Hotkeys . BufferScreenToFront,    "control rshift return");
  4901.         strcpy(Hotkeys . SkipDialEntry,        "control lshift rshift return");
  4902.         strcpy(Hotkeys . AbortARexx,        "lshift rshift escape");
  4903.  
  4904.         Hotkeys . CommodityPriority    = 0;
  4905.         Hotkeys . HotkeysEnabled    = TRUE;
  4906.     }
  4907.  
  4908.         /* Initialize the data flow parser. */
  4909.  
  4910.     FlowInit(TRUE);
  4911.  
  4912.         /* Set up the edit list labels for the phonebook. */
  4913.  
  4914.     if(!(EditList = (struct List *)AllocVecPooled(sizeof(struct List),MEMF_ANY)))
  4915.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4916.  
  4917.     NewList(EditList);
  4918.  
  4919.     if(!(EditLabels = (STRPTR *)AllocVecPooled(sizeof(STRPTR) * (MSG_PHONEPANEL_RATES_TXT - MSG_PHONEPANEL_SERIAL_TXT + 1),MEMF_ANY | MEMF_CLEAR)))
  4920.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4921.  
  4922.     for(i = MSG_PHONEPANEL_SERIAL_TXT ; i <= MSG_PHONEPANEL_RATES_TXT ; i++)
  4923.     {
  4924.         if(Node = (struct Node *)AllocVecPooled(sizeof(struct Node) + strlen(LocaleString(i)) + 2,MEMF_ANY))
  4925.         {
  4926.             EditLabels[i - MSG_PHONEPANEL_SERIAL_TXT] = Node -> ln_Name = (STRPTR)(Node + 1);
  4927.  
  4928.             Node -> ln_Name[0] = ' ';
  4929.  
  4930.             strcpy(&Node -> ln_Name[1],LocaleString(i));
  4931.  
  4932.             AddTail(EditList,Node);
  4933.         }
  4934.         else
  4935.             return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4936.     }
  4937.  
  4938.         /* Set up parsing jump tables. */
  4939.  
  4940.     if(!(SpecialTable = (JUMP *)AllocVecPooled(256 * sizeof(JUMP),MEMF_CLEAR | MEMF_ANY)))
  4941.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4942.  
  4943.     for(i = 0 ; i < sizeof(SpecialKeys) / sizeof(struct SpecialKey) ; i++)
  4944.         SpecialTable[SpecialKeys[i] . Key] = (JUMP)SpecialKeys[i] . Routine;
  4945.  
  4946.     if(!(AbortTable = (JUMP *)AllocVecPooled(256 * sizeof(JUMP),MEMF_ANY)))
  4947.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4948.  
  4949.     for(i = 0 ; i < 256 ; i++)
  4950.     {
  4951.         switch(AbortMap[i])
  4952.         {
  4953.             case 0:    AbortTable[i] = (JUMP)ParseCode;
  4954.                 break;
  4955.  
  4956.             case 1:    AbortTable[i] = (JUMP)DoCancel;
  4957.                 break;
  4958.  
  4959.             case 2:    AbortTable[i] = (JUMP)DoNewEsc;
  4960.                 break;
  4961.  
  4962.             case 3:    AbortTable[i] = (JUMP)DoNewCsi;
  4963.                 break;
  4964.         }
  4965.     }
  4966.  
  4967.         /* Create all generic lists. */
  4968.  
  4969.     for(i = GLIST_UPLOAD ; i < GLIST_COUNT ; i++)
  4970.     {
  4971.         if(!(GenericListTable[i] = CreateGenericList()))
  4972.             return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4973.     }
  4974.  
  4975.         /* Load the trap settings. */
  4976.  
  4977.     strcpy(LastTraps,    Config -> PathConfig -> DefaultStorage);
  4978.     AddPart(LastTraps,    "trap.prefs",MAX_FILENAME_LENGTH);
  4979.  
  4980.     WatchTraps = TRUE;
  4981.  
  4982.     LoadTraps(LastTraps,GenericListTable[GLIST_TRAP]);
  4983.  
  4984.         /* Create the special event queue. */
  4985.  
  4986.     if(!(SpecialQueue = CreateMsgQueue(NULL,0)))
  4987.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  4988.  
  4989.         /* Set up the serial driver. */
  4990.  
  4991.     if(Error = CreateSerial())
  4992.     {
  4993.         MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error);
  4994.  
  4995.         DeleteSerial();
  4996.     }
  4997.     else
  4998.     {
  4999.         if(SerialMessage)
  5000.         {
  5001.             MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SerialMessage);
  5002.  
  5003.             SerialMessage = NULL;
  5004.         }
  5005.     }
  5006.  
  5007.         /* Get a signal bit. */
  5008.  
  5009.     if((CheckBit = AllocSignal(-1)) == -1)
  5010.         return(LocaleString(MSG_TERMINIT_FAILED_TO_GET_CHECK_SIGNAL_TXT));
  5011.  
  5012.     if(!(TimePort = (struct MsgPort *)CreateMsgPort()))
  5013.         return(LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT));
  5014.  
  5015.     if(!(TimeRequest = (struct timerequest *)CreateIORequest(TimePort,sizeof(struct timerequest))))
  5016.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_IOREQUEST_TXT));
  5017.  
  5018.     if(OpenDevice("timer.device",UNIT_VBLANK,TimeRequest,0))
  5019.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_TIMER_DEVICE_TXT));
  5020.  
  5021.     TimerBase = &TimeRequest -> tr_node . io_Device -> dd_Library;
  5022.  
  5023.         /* Add the global term port. */
  5024.  
  5025.     if(!TermPort)
  5026.     {
  5027.         if(!(TermPort = (struct TermPort *)AllocVec(sizeof(struct TermPort) + 11,MEMF_PUBLIC|MEMF_CLEAR)))
  5028.             return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_GLOBAL_PORT_TXT));
  5029.         else
  5030.         {
  5031.             NewList(&TermPort -> ExecNode . mp_MsgList);
  5032.  
  5033.             InitSemaphore(&TermPort -> OpenSemaphore);
  5034.  
  5035.             TermPort -> ExecNode . mp_Flags            = PA_IGNORE;
  5036.             TermPort -> ExecNode . mp_Node . ln_Name    = (char *)(TermPort + 1);
  5037.  
  5038.             strcpy(TermPort -> ExecNode . mp_Node . ln_Name,"term Port");
  5039.  
  5040.             AddPort(&TermPort -> ExecNode);
  5041.         }
  5042.     }
  5043.  
  5044.         /* Keep another term task from removing the port. */
  5045.  
  5046.     TermPort -> HoldIt = TRUE;
  5047.  
  5048.         /* Install a new term process. */
  5049.  
  5050.     ObtainSemaphore(&TermPort -> OpenSemaphore);
  5051.  
  5052.     TermPort -> OpenCount++;
  5053.  
  5054.     TermPort -> HoldIt = FALSE;
  5055.  
  5056.     TermID = TermPort -> ID++;
  5057.  
  5058.     ReleaseSemaphore(&TermPort -> OpenSemaphore);
  5059.  
  5060.         /* Set up the ID string. */
  5061.  
  5062.     if(TermID)
  5063.         SPrintf(TermIDString,"TERM.%ld",TermID);
  5064.     else
  5065.         strcpy(TermIDString,"TERM");
  5066.  
  5067.     if(RexxPortName[0])
  5068.     {
  5069.         WORD i;
  5070.  
  5071.         for(i = 0 ; i < strlen(RexxPortName) ; i++)
  5072.             RexxPortName[i] = ToUpper(RexxPortName[i]);
  5073.  
  5074.         if(FindPort(RexxPortName))
  5075.             RexxPortName[0] = 0;
  5076.     }
  5077.  
  5078.     if(!RexxPortName[0])
  5079.         strcpy(RexxPortName,TermIDString);
  5080.  
  5081.         /* Install the hotkey handler. */
  5082.  
  5083.     SetupCx();
  5084.  
  5085.         /* Allocate the first few lines for the display buffer. */
  5086.  
  5087.     if(!CreateBuffer())
  5088.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_VIEW_BUFFER_TXT));
  5089.  
  5090.     if(!(XprIO = (struct XPR_IO *)AllocVec(sizeof(struct XPR_IO),MEMF_ANY|MEMF_CLEAR)))
  5091.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_PROTOCOL_BUFFER_TXT));
  5092.  
  5093.         /* Set up the external emulation macro data. */
  5094.  
  5095.     if(!(XEM_MacroKeys = (struct XEmulatorMacroKey *)AllocVecPooled((2 + 10 * 4) * sizeof(struct XEmulatorMacroKey),MEMF_ANY|MEMF_CLEAR)))
  5096.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_MACRO_KEY_DATA_TXT));
  5097.  
  5098.     strcpy(LastXprLibrary,Config -> TransferConfig -> DefaultLibrary);
  5099.  
  5100.     ProtocolSetup(FALSE);
  5101.  
  5102.         /* Load a keymap file if required. */
  5103.  
  5104.     if(Config -> TerminalConfig -> KeyMapFileName[0])
  5105.         KeyMap = LoadKeyMap(Config -> TerminalConfig -> KeyMapFileName);
  5106.  
  5107.     if(!(TermRexxPort = (struct MsgPort *)CreateMsgPort()))
  5108.         return(LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT));
  5109.  
  5110.         /* If rexxsyslib.library opens cleanly it's time for
  5111.          * us to create the background term Rexx server.
  5112.          */
  5113.  
  5114.     if(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME,0))
  5115.     {
  5116.             /* Create a background process handling the
  5117.              * rexx messages asynchronously.
  5118.              */
  5119.  
  5120.         Forbid();
  5121.  
  5122.         if(RexxProcess = (struct Process *)CreateNewProcTags(
  5123.             NP_Entry,    RexxServer,
  5124.             NP_Name,    "term Rexx Process",
  5125.             NP_Priority,    5,
  5126.             NP_StackSize,    8192,
  5127.             NP_WindowPtr,    -1,
  5128.         TAG_END))
  5129.         {
  5130.             ClrSignal(SIG_HANDSHAKE);
  5131.  
  5132.             Wait(SIG_HANDSHAKE);
  5133.         }
  5134.  
  5135.         Permit();
  5136.  
  5137.         if(!RexxProcess)
  5138.             return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_AREXX_PROCESS_TXT));
  5139.     }
  5140.  
  5141.         /* Install the public screen name, assumes that the user
  5142.          * wants the window to be opened on the screen, rather than
  5143.          * opening a custom screen.
  5144.          */
  5145.  
  5146.     if(SomePubScreenName[0])
  5147.     {
  5148.         strcpy(Config -> ScreenConfig -> PubScreenName,SomePubScreenName);
  5149.  
  5150.         Config -> ScreenConfig -> Blinking    = FALSE;
  5151.         Config -> ScreenConfig -> FasterLayout    = FALSE;
  5152.         Config -> ScreenConfig -> UseWorkbench    = TRUE;
  5153.  
  5154.         SomePubScreenName[0] = 0;
  5155.     }
  5156.  
  5157.     CreateQueueProcess();
  5158.  
  5159.     Forbid();
  5160.  
  5161.     RendezvousSemaphore . rs_Semaphore . ss_Link . ln_Name = RexxPortName;
  5162.     RendezvousSemaphore . rs_Semaphore . ss_Link . ln_Pri  = -127;
  5163.  
  5164.     AddSemaphore(&RendezvousSemaphore);
  5165.  
  5166.     Permit();
  5167.  
  5168.     if(DoIconify)
  5169.         return(NULL);
  5170.     else
  5171.     {
  5172.             /* Create the whole display. */
  5173.  
  5174.         if(Result = CreateDisplay(TRUE))
  5175.             return(Result);
  5176.         else
  5177.         {
  5178.             PubScreenStuff();
  5179.  
  5180.             return(NULL);
  5181.         }
  5182.     }
  5183. }
  5184.